Name
ReDim Statement
Syntax
ReDim [Preserve]varname(subscripts)_ [,varname(subscripts)] ...
PreserveUse: Optional
Type: Keyword
Preserves the data within an array when changing its single or its last dimension.
varnameUse: Required
Data Type: Any
Name of the variable.
subscriptsUse: Required
Number of elements and dimensions of the array, using the following syntax:
upper[,upper] . . .where
upperis the upper bound of a particular array dimension.
Description
Used within a procedure to resize and reallocate storage space for a dynamic array.
Rules at a Glance
A dynamic array is created using a
Private,Public, orDimstatement with empty parentheses. Only dynamic arrays created in this manner can be resized using theReDimstatement. There is no limit to the number of times you can redimension a dynamic array.Use of the
Preservekeyword allows you to retain the current values within the array, but it also places several limitations on how theRedimstatement can be used:Only the last dimension of an array can be resized.
The number of dimensions can’t be changed.
Only the upper bound of the array can be changed.
If you reduce either the number of elements of the array or the number of dimensions in the array, data in the removed elements is permanently lost, irrespective of the use of the
Preservekeyword.
Programming Tips and Gotchas
You can pass an array by reference to a procedure, redimension it within the procedure, and return the modified array to the calling program. This is illustrated ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access