<< Click to Display Table of Contents >> Arrays |
SoftMaker Basic supports one- and multi-dimensional arrays. In arrays, series of values can be stored under a uniform name. Each value in the array can be accessed by an index.
All elements of an array have the same data type. The following data types are allowed: Integer, Long, Single, Double or String.
Note: In some Basic variants, arrays can be used without previous declaration. In SoftMaker Basic, this is not allowed. Arrays must be declared before their first use, using either Dim or Static
To set the size of an array, you indicate the upper limit and optionally the lower limit for the index. Only fixed values are allowed, variables are not acceptable.
If the lower limit is omitted, the value defined by Option Base is taken – by default, this is 0.
Dim a(10) As Integer ' a(0)..a(10)
Dim b(-10 To 10) As Double ' b(-10)..b(10)
You can use loops to efficiently access the elements of arrays. For example, the following For loop initializes all elements of the array "A" with 1:
Static A (1 To 20) As Integer
Dim i As Integer
For i = 1 To 20
A(i) = 1
Next i
Multi-dimensional arrays
Arrays can also have multiple dimensions, for example:
Static a(10, 10) As Double ' two-dimensional
Dim b(5, 3, 2) ' three-dimensional