If the array is determined to be static, its number of dimensions and maximum subscript values are fixed and may not be changed. Space for the array is allocated.
If the array is determined to be dynamic, only its number of dimensions is fixed and may not be changed. The dim statement is an executable statement: when the statement is executed while the program is running, the maximum subscript expressions are evaluated, the maximum subscript values are fixed and space for the array is allocated. A dynamic array may be dimensioned more than once provided it is erased in the interim (see erase). The elements of a dynamic array may not be used before the initial dim statement is executed and while it is erased. An array which is a formal parameter to a subprogram may not be dimensioned.
In the absence of an explicit dim statement for an array, the array is assumed to be static with as many dimensions as there are subscripts in its first reference and with 10 as the maximum value for each subscript.
The minimum subscript value for all arrays in a program is specified by the option base statement and may be either zero or one. The default minimum value is zero.
By default, an array that appears within a subprogram is different from an array with the same name and type outside that subprogram. That is, the scope of the array does not include the subprogram. If the word shared is used in the dim statement, the scope of an array so declared includes the subprograms of the module. Nevertheless, within any particular subprogram, this declaration of the array may be nullified and the default restored by a static declaration (see static) or by a declaration as a formal parameter. This version of the dim statement may not be used within a user defined function or subprogram.
dim n(12 + 1), a$(3, 3) data 13.2, 24, 2, 63, 70, 6.3, 50 data 3, 42, 70, 42, 3, 89 for i = 0 to 12 read n(i) next i data JONES, JOHN, PAUL data "AKRON, OHIO", CANTON, TOLEDO data CLEVELAND, COLUMBUS, CINCINNATI for i = 0 to 2 : for j = 0 to 2 read a$(i, j) next j, i print n(3); a$(2, 0)produces
63 CLEVELANDThis example dimensions two arrays: a one-dimensional numeric array named n with 13 elements, n(0) through n(12), and a two-dimensional string array named a$, with three rows and three columns.
The following program fragment reads from a file the length of a list which is used to allocate a dynamic array. The list of coordinate pairs is read from the file and stored in the array.
open "coordinates" for input as #1 input #1, n dim xy(n, 2) for i = 1 to n input #1, xy(n, 1), xy(n, 2) next i close #1
If the value of a subscript is greater than the maximum allowed or less than the minimum allowed, a "Subscript out of range" error occurs.
from The Basmark QuickBASIC Programmerís Manual by Lawrence Leinweber