The dimension statement establishes a specific number of storage locations for a matrix of variables.
dimension array.var({rows{,cols}})
dim
array.var | Can be of one or two dimensions only. Individual elements within an array are accessed by appending the element number, enclosed in parentheses, to the array variable. |
rows | Number of rows in the array. Can be any valid numeric expression. |
cols | Number of columns in the array. Can be any valid numeric expression. |
A dimension statement without the number of elements specified (such as in the case dim a()) can only be used in a subroutine. FlashBASIC or BASIC run time determines the number of elements after a matread.
An array must be dimensioned prior to being referenced within a program. After an array has been dimensioned, it can be redimensioned later within a program. When the dimensioning parameters are changed, the new array:
retains those elements with the same indexes that were in the old array.
initializes any new elements to an unassigned state.
loses any un-referenced elements (those elements in the old array with indexes not present in the new array).
If an array is passed to a subroutine in an argument list, it cannot be redimensioned within the subroutine. A passed array can only be dimensioned once within a subroutine. Local arrays can be redimensioned as necessary. When arrays are dimensioned both in a subroutine and within the calling program, the dimensions specified in the calling program supersedes those specified within the subroutine if the subroutine’s array was dimensioned as an empty dimension. The number of dimensions must be the same in both the calling program and called subroutine.
rec is a single dimensional array (vector) with 20 subscripted variables. table is a two-dimensional array (matrix) with 9 subscripted variables.
dim rec(20),table(3,3)
In D3, dimension can be handled by FlashBASIC or BASIC run time.
x = 20 dim a(x) input y dim b(y) dim c(x,y)
This example illustrates a dim statement without arguments. It resolves the size of the array after the matread.
subroutine process.receipt(receipt.item) dim work.list() ... matread work.list...