Original Author Paul Laughton, 2011
Page 40
De Re BASIC!
Traits array to have two dimensions such that Traits$[5,2] = "Has four legs". If someone asked what are
the traits of cat, search Animals$[index] until "Cat" is found at index =5. Index=5 can then be used to
access Traits[index,[ {1|2|3}].
BASIC! arrays can have any number of dimensions of any size.
BASIC! arrays are "one-based". This means that the first element of an array has an index of "1".
Attempting to access an array with an index of "0" (or less than 0) will generate a run-time error.
Before an array can be used, it must be dimensioned using the DIM command. The DIM command tells
BASIC! how many indices are going to be used and the sizes of the indices. Some BASIC! Commands
automatically create a one-dimensional array. Auto-dimensioned array details will be seen in the
description of those commands.
Note: It is recommended that the List commands (see below) be used in place of one-dimensional
arrays. The List commands provide more versatility than the Array commands.
Array Segments
Some BASIC! Commands take an array as an input parameter. If the array is specified with nothing in the
brackets (for example, "Animals$[]"), then the command reads the entire array.
Most of these commands allow you to limit their operation to a segment of the array, using the notation
"Array[start, length]", where both "start" and "length" are numeric expressions.
For example, you can write "Animals$[2,3]". Usually that means "the animal at row 2 and column 3 of a
two dimensional array called Animals$". When used to specify an array segment, it has a different
meaning: "read only the segment of the Animals$ array that starts at index 2 and includes 3 items".
Notice that this notation applies only to one-dimensional arrays. In fact, it treats all arrays as one-
dimensional, regardless of how they are declared.
Both of the expressions in the "[start, length]" pair are optional. If the "start" value is omitted, the
default starting index is 1. If the "length" value is omitted, the default is the length from the starting
index to the end of the array. If both are omitted, the default is to use the entire array.
Array Commands
These commands all operate on Arrays. Commands operate on both numeric and string arrays, unless
otherwise indicated.
Dim Array[<nexp>{, <nexp> } ... ] {, Array[<nexp>{, <nexp> } ... ] } ...
The Dim command tells BASIC! how many dimensions an array will have and how big those dimensions
are. BASIC! creates the array, reserving and initializing memory for the array data. All elements of a
numeric array are initialized to the value 0.0. String array elements are initialized to the empty string, "".
If you Dim an array that already exists, the existing array is destroyed and a new one created.