Dynamic Size Arrays
To declare a dynamic sized array, the array must first be declared using the dim
statement with an empty pair of parentheses following the array name. For example:
Dim ArrayName( ) As Integer
Once declared as dynamic in this manner, the array can then ONLY be resized within a function or subroutine using the redim
statement.
ReDim ArrayName(20) As Integer
Note: You cannot resize an array whose size was predefined in its initial declaration.
In the above examples, the first declaration creates an array with 0 elements. The second recreates the array to contain 21 elements, with index numbers running from 0 to 20, unless the option base
statement has been set previously in the code module (file), in which case the array will contain 20 elements with index numbering ranging from 1 to 21.
Unless specifically defined in the array declaration statement, default lower bound settings are used. The default lower bound is zero, unless set by the module option base
statement setting. For more information on bounds, see "Array Subscripts in CitectVBA."
Redim
erases all values the array may have held. To preserve the contents of the array when resizing, precede the Redim statement with the preserve
keyword.
Preserve ReDim ArrayName(20) As Integer
Redimensioning an array to a smaller value, will erase any values it may have contained in the removed portions.
Arrays declared (using the dim
statement within procedures,) do not retain their values between procedure calls in CitectVBA.
See Also
Published June 2018