Click to See Complete Forum and Search --> : ReDim Preserve... anyone know?


Dubz
May 18th, 2001, 11:33 AM
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?

coolbiz
May 18th, 2001, 11:54 AM
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

Dubz
May 18th, 2001, 11:59 AM
You are absolutly right! Thank you very much.