Arrays are similar to normal variables except they contain one or more entries. Each entry is treated like a variable.
Here is an example of creating an array in Ozapell Basic:
The variable MYARRAY is declared and given the value of 0. The ARRAY variable is given MYARRAY. RANGE will specify how many entries will be in the array. DIM changes the variable MYARRAY into an array containing 100 entries with the value of 0 in each.
If MYARRAY had been declared with a different initial value, then every entry would contain that value instead.
Here’s an example of an array working with strings:
This code will result in MYSTRINGARRAY containing 20 entries with the string “HELLO WORLD” in them.
Here is an example of an array of colors:
In this example, an array called COLORS is created with 3 entries containing the color black. Then each entry is initialized with a different color.
Arrays in Ozapell Basic will automatically advance to the next entry when the array is read or new data is written to it. If the array reaches the end, it will automatically circle back to the first entry.
The array index can also be set manually. This would be useful for random access to the array’s data.
Assuming the previous array COLORS has been declared…
This example will change the index (next entry to be used) in the array to 0. In Ozapell Basic, all arrays are indexed starting from 0. The first entry in every array is 0, the second entry is 1, etc.