dimension statement

The dimension statement establishes a specific number of storage locations for a matrix of variables.


 dimension array.var({rows{,cols}})




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 re-dimensioned 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 re-dimensioned within the subroutine. A passed array can only be dimensioned once within a subroutine. Local arrays can be re-dimensioned as necessary. When arrays are dimensioned both in a subroutine and within the calling program, the dimensions specified in the calling program supersede 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.


Example 1

  • rec is a single dimensional array (vector) with 20 sub-scripted variables.
  • table is a two-dimensional array (matrix) with 9 subscripted variables.
 dim rec(20),table(3,3)

Example 2

The dim statement can be handled by FlashBASIC or BASIC runtime.

 x = 20
 dim a(x)
 input y
 dim b(y)
 dim c(x,y)

Example 3

This example illustrates a dim statement without arguments. It resolves the size of the array after the matread.

 subroutine process.receipt(work.list)
 dim work.list()
 matread work.list...