ReDim Statement

Language Items List

Definition:

Used at the procedure level to declare dynamic-array variables and allocate or reallocate storage space.

Syntax:

ReDim [Preserve]variable(subscripts) [,variable(subscripts)]


Syntax Description


Preserve An optional keyword that allows the data in an existing array to remain unchanged when you resize the last dimension.

subscripts Dimensions of an array variable. Multiple dimensions are allowed and can be declared using the subscripts syntax that is described in the text that follows.

The argument subscripts consists of the following syntax:

[lower To]upper[,lower To]upper]...'


Syntax Description


lower Specifies the lower limit of an array dimension. It can be a range of subscripts; negative numbers are allowed.

To Reserved word that separates lower and upper values.

upper Specifies the upper limit of an array dimension. It can be a range of subscripts; negative numbers are allowed.

Details:

The ReDim statement is typically used to size or resize a dynamic array that has already been declared with the Dim statement.

With ReDim you can change the number and size of dimensions of an array.

If you use the optional Preserve reserved word, you can change the size of the last array dimension only and still preserve the contents of the array. For example, if your array has two or more dimensions, you cannot resize the first one and expect to preserve the values in the array. The following example shows how you can increase the size of the last dimension of a dynamic array without destroying any existing array data.

ReDim Y(5, 5, 5)
...
ReDim Preserve Y(5, 5, 10)

When variables are initialized, numeric variables are initialized to 0, and strings are initialized as zero-length strings.

See Also:

Dim Statement
Static Statement