There are two kinds of arrays in Gambas:

"Java-like" arrays

They are objects of the following classes:

Integer[], String[], Object[], Date[], Variant[].
They have only one dimension.

You declare them this way: they are always void at startup.

DIM MyArray AS NEW Integer[]
They are dynamic, and have a lot of useful methods applying to them.

"Native" arrays

You declare them this way:

DIM MyArray[Dim1, Dim2, ... ] AS Integer/String/...

You can have up to eight dimensions.

They are NOT objects. They are allocated on the stack if you declare them local to a function, or inside the object data if you declare them global.

They are NOT dynamic. They can't grow or shrink once declared. You can only only put an get data into them.

(answered by Benoit in the Gambas-user mailing list)

Example for a 3d native array

The array is filled with the integers from 0 to 26

You need a commandbutton on your form to get it going.

PUBLIC SUB Button1_Click()
 DIM i AS Integer
  DIM ii AS Integer
   DIM iii AS Integer
DIM Matrix[3, 3, 3] AS Integer 
 FOR i = 0 TO 2
  FOR ii = 0 TO 2
   FOR iii = 0 TO 2
    PRINT i, ii , iii
    Matrix[i, ii, iii] = i*9 + ii*3 + iii
    PRINT Matrix[i, ii, iii]
   NEXT
  NEXT
 NEXT
END

-- ReinerHoffmann - 14 Feb 2004

-- NelsonFerraz - 30 Aug 2003