Home > cat > arraydecl 
 fr de es it nl pl pt pt_BR mk sq ca hu cs tr ar fa id vi ko ja ru zh zh_TW eo
Previous  Next  Edit  Rename  Undo  Refresh  Search  Administration  
Documentation
History
 
Array Declaration
DIM Identifier AS [ NEW ] Datatype [ Array dimensions ... ]

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

Example

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

In Gambas 3, any datatype can be used as array element.

DIM aLabel AS NEW Label[12, 12]
DIM aResult AS NEW String[][12] ' An array of string arrays!

Dimensions

The array can have several dimensions, up to a maxium of eight.

Example

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] 'will report error

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.

Embedded arrays

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

An embedded 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.

An embedded array cannot be public, and you cannot initialize it.

In Gambas 3, embedded arrays cannot be used as local variables anymore. But they can be public!

Example

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

See also

Variable Declaration, Local Variable Declaration, Using reserved keywords as identifiers, Structure declaration, dynamic array