ReDim
Statement
Allocates new memory for an array variable.
Syntax
ReDim name ( dimensions ) [ , name ( dimensions ) ]…
Parts
name
- An array variable.
dimensions
- One or more integer expressions, with a comma between each, all between parentheses.
Instructions
You can use the statement ReDim
to change the size of one or more dimensions of an array variable.
If you make a large array and many elements are not used, ReDim
can release memory with a smaller array.
But, if your array is too small, ReDim
can add elements.
You use ReDim
only with arrays.
You cannot use ReDim
with scalars (variables that contain only one value) or structures.
Rules
- Array bounds
- Each dimension has a minimum index of zero and a maximum index that you supply. The supplied number is not the size of the dimension. The size of the dimension is the maximum index plus one.
- The number of dimensions (rank) must be the same as those in the array declaration.
- Data type
ReDim
cannot change the data type of the elements of an array.- Rank
ReDim
cannot change the number of dimensions (rank) of the array.
Behavior
- Replacement array
ReDim
releases the memory used by the array, then makes a new array with the same rank. The new array replaces the released array in the array variable.- Initialization
ReDim
initializes the elements of the new array with the default value for the data type.
Examples
TODO