DIM Statement

Previous  Next

 

DIM var-name[(dimensions)] AS type

 


 

Declare a local variable of type.  Local variables are only accessible to the current program and all it's subroutines and functions.  A variable DIMed in a FUNCTION or SUB is only available in that function or sub and will not be available after return.  It is important to note however, that local variables will retain their contents between calls to FUNCTIONs or SUBs similar to a local variable declared as static in C/C++.

 

To declare an array, set the dimensions.  Up to 4 dimension can be used.  The format of the dimensions are;

 

( dim1, dim2, dim3, dim4 )

 

Dimensions are omitted from left to right.  For example, ( 60, 4, 3 ) would be the same as ( 0, 60, 4, 3 ).  However, please note, that you can't specify a zero dimension in the DIM statement.  When indexing an array, they are indexed as they are dimensioned. For example; to loop through the above dimensions the code would look something like;

 

DIM frames( 60, 4, 3 ) AS REAL

 

FOR frame = 1 TO 60

  FOR point = 1 TO 4

     FOR d = 1 To 3

        frames( frame, point, d ) = 0

     NEXT d

  NEXT point

NEXT frame

 

Note that option base is set to 1 in the example above.

 

Type can be one of the following:

 

INTEGER

REAL

STRING

REFERENCE

MODULE

HANDLE

 

Examples:

 

DIM kalle(4) AS REAL

DIM nisse AS INTEGER

DIM str AS STRING

DIM ptr AS REFERENCE

DIM pelle(20,3) AS INTEGER