Arrays
From REALbasicWiki
Arrays are defined by using parenthesis ie: () when using a dim statement.
You can make arrays of almost anything.
For example:
Creating
Dim myArray(10) as Integer Dim MyObjArray(0) as MyClass Dim EmptyArray(-1) as String
The first statement dimensions array elements myArray(0) through myArray(10)
The second statement dimensions a single array element MyObjArray(0).
Note that MyObjArray(0) is nil because it is an object reference.
You must do the following to put an object in it:
MyObjArray(0) = new MyClass
The third statement creates a name for an array, but it does not exist yet.
You can use the RB statement ReDim or the array class method Append to add to the array:
Adding to the Array End
EmptyArray.Append("Hello") // creates first element containing "Hello"
After that statement, EmptyArray(0) contains the string "Hello"
ReDimension
Redim EmptyArray(2)
After that statement EmptyArray(0) contains "Hello" and EmptyArray(1) contains "" and EmptyArray(2) contains "".
Number of Elements
The method UBound() provides the highest index valid for the array. UBound(EmptyArray) will return 2 after the Redim statement.
Removing from Array
The method Remove() removes the item from an array. The following removes element 1 from the array:
EmptyArray.Remove(1)
