ReDim statement (LotusScript® Language)

Declares a dynamic array and allocates storage for it, or resizes an existing dynamic array.

Syntax

ReDim [ Preserve ] arrayName ( bounds ) [ As type]

[ , arrayName ( bounds ) [ As type ] ] ...

Elements

Preserve

Optional. If you've already declared arrayName, LotusScript® preserves the values currently assigned to it. If you omit Preserve, LotusScript® initializes all elements of the array, depending on the data type of the array variable.

Data type of array variable

Initial value of array element

Boolean, Byte, Integer, Long, Single, Double, or Currency

0

Fixed-length String

A string of the specified length, filled with the Null character (Chr(0))

Variable-length String

The empty string ("")

Variant

EMPTY

Class

NOTHING

User-defined data type

The initial value of each element's own data type

arrayName

The name of an array to be declared or resized. The arrayName must designate an array; it cannot be a Variant variable containing an array.

bounds

A comma-separated list of dimension bounds for arrayName. Each set of dimension bounds has the following form:

[ lowerBound To ] upperBound

The lowerBound is the minimum subscript allowed for the dimension, and upperBound is the maximum. If you don't specify a lowerBound, the lower bound for the array dimension defaults to 0, unless the default lower bound has been changed to 1 using the Option Base statement.

Array bounds must fall in the range -32768 to 32767, inclusive.

type

Optional. A valid LotusScript® data type, user-defined type, or class that specifies the data type of arrayName.

You cannot change the data type of an existing array. If arrayName was declared and type is specified in the current ReDim statement, type must match the original data type of arrayName.

Usage

A ReDim statement allocates storage for a dynamic array. You can resize the array with additional ReDim statements as often as you want. Each time you resize the array, LotusScript® reallocates the storage for it.

Unlike a Dim statement, ReDim cannot specify an array as Private, Public, or Static. To specify a dynamic array with one of these characteristics, declare it first in a Dim statement. If you declare a dynamic array with a Dim statement, LotusScript® doesn't allocate storage for the array elements. You can't actually use the array in your script until you allocate storage with ReDim.

Arrays can have up to 8 dimensions. The first ReDim statement for an array sets the number of dimensions for the array. Subsequent ReDim statements for the array can change the upper and lower bounds for each dimension, but not the number of dimensions.

If Preserve is specified, you can change only the upper bound of the last array dimension. Attempting to change any other bound results in an error.

Do not use ReDim on a fixed array (an array already declared and allocated by a Dim statement).

If you're using ForAll on a container variable that is an array of arrays, do not ReDim the reference variable (this generates the "Illegal ReDim" error).

Example