CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2001
    Posts
    27

    ReDim Preserve... anyone know?

    Greetings! In a module I have declared the following:
    Public Const TOTAL = 5
    Public Points(TOTAL, 1)
    Later in the code (within a form) I have the following:
    ReDim Preserve Points(TOTAL, 5)
    However this crashes stating that the array has already been dimentioned. Any thoughts?


  2. #2
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: ReDim Preserve... anyone know?

    Yea ... by declaring PUBLIC POINTS(TOTAL, 1), you're basically declaring a STATIC ARRAY. Means you CANNOT re-dimension it any longer. To declare dynamic array, PUBLIC POINTS() AS <type_name>. Then you need to init the array for the first time such as REDIM POINTS(TOTAL,0). Note that with multi-dimensional array, when you use PRESERVE with REDIM, you can only REDIM the last dimension. So REDIM PRESERVE POINTS(TOTAL,10) is valid while REDIM PRESERVE POINTS(TOTAL+10, 0) will give you run-time error. But you can always do REDIM POINTS(TOTAL+10,0) which of course basically reset the whole content of the array.

    -Cool Bizs

    Good Luck,
    -Cool Bizs

  3. #3
    Join Date
    Jan 2001
    Posts
    27

    Re: ReDim Preserve... anyone know?

    You are absolutly right! Thank you very much.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured