Home / lang / arraydecl 
Array Declaration
Syntax
DIM Identifier AS [ NEW ] Native Datatype [ Array dimensions ... ]

Note that you can use any expression for specifying array dimensions.

Examples

DIM aWords AS NEW String[WORD_MAX * 2]
DIM aMatrix AS NEW Float[3, 3]

Dimensions

The variables can have dimensions, Integer variables may have a maximum of 8 dimensions.

DIM iGroupc AS NEW Integer[27, 9]
DIM iFieldr AS NEW Integer[9]
DIM iX9X AS NEW Integer[3, 4, 5, 2, 3, 2, 2, 4, 2]
DIM fX9X AS NEW Float[3, 4, 5, 2, 3, 2, 2, 4, 2]

The name "DIM" for this declaration comes from the sixties, where BASIC variables did not need to be declared, except variables with dimensions.

Gambas uses brackets [ ] instead of braces ( ) to declare and use dimensions.

Static arrays

Syntax
[ STATIC ] { PUBLIC | PRIVATE } Identifier [ Array dimensions ... ] AS Native Datatype

A static array is an array that is allocated directly inside the object where it is declared.

Such an array cannot be shared, and is destroyed with the object.

A static array cannot be public, and you cannot initialize it.

Do not use static arrays as local variables. It works at the moment, but may be removed in the future.

PRIVATE Handles[8] AS Label
STATIC PRIVATE TicTacToe[3, 3] AS Integer

See also

Variable Declaration  Local Variable Declaration