Reallocates storage space for arrays.
ReDim [Preserve] varname [size1 [, ...] ]
The ReDim statement is used to size or resize an array variable varname. You can use the ReDim statement repeatedly to change the number of elements. The statement cannot be used to change the number of dimensions of the array.
If the Preserve is not used the array is initialized and its values are reset to their default initial value (zero for numeric types, empty string for string, etc.). The variable initial value as set from the variable Value property page is not used.
If you use the Preserve keyword, the data stored in the array is preserved. New elements added will have the data type default initial value. while existing elements will keep their values.
The ReDim statement is useful for reducing the amount of memory that the application consumes. Once the array is no longer used you can use the ReDim to decrease its size.
You cannot ReDim an array that resides inside a structure. Structure have fixed width that cannot be changed. You can use a Variant data type structure field that contain an array and use the VarDimSize to get or change it's dimension.
The following example uses ReDim to allocate array as required by a Scope instruments to calculate the mean value. After the calculation is complete the array size is reduced to a minimum.
! read data to array and calc mean value
Scope Read Data Size (dwSize)
ReDim adwReadings [dwSize]
Scope Read Data (adwReadings, dwSize)
TestResult=Mean (adwReadings)
! reduce the array size to 1 since we no longer need it
ReDim adwReadings[1]