7.2.2.2 Executable DIM Statements
Executable DIM statements have at least one variable bound.
Bounds can be constants or simple variables, but at least one
bound must be a variable. Executable DIM statements let you
redimension an array at run time. The bounds of the array
can become larger or smaller, but the number of dimen-
sions cannot change. For example, you cannot redimension a
four-dimensional array to be five-dimensional.
The executable DIM statement cannot be used on arrays in
COMMON, MAP, DECLARE, or declarative DIM state-
ments, nor on virtual arrays or arrays received as formal
parameters.
Whenever an executable DIM statement executes, it reini-
tializes the array. If you change the values of an executable
DIM statement, the initial values are reset each time the
DIM statement is executed.
In the following example, the second DIM statement reini-
tializes the array real_array ; therefore, real_array(1%)
equals zero in the second PRINT statement:
X% = 10%
Y% = 20%
DIM real_array(X%)
real_array(1%) = 100
PRINT real_array(1%)
DIM real_array(Y%)
PRINT real_array(1%)
END
Output
100
0
You cannot reference an array named in an executable
DIM statement until after the DIM statement executes. If
you reference an array element declared in an executable
DIM statement whose subscripts are larger than the bounds
specified in the last execution of the DIM statement, BASIC
signals the run-time error ``Subscript out of range'' (ERR =
55), provided subscript checking is enabled.