Professional Documents
Culture Documents
You use arrays to store multiple variables of the same type within
one data item. Each variable can be referred to with the construction
array_name(index). For example, the first element in a one-
dimensional array is array_name(1).
Long arrays
The number in parentheses after the array name specifies the number
of longs that can be stored in the array.
You declare two-dimensional long arrays as follows:
LONG lng_array(2,4)
The first number after the array name indicates the number of
dimensions in the array. The second number indicates the number of
longs that can be stored in each dimension. The following diagram
illustrates a two-dimensional array as a matrix:
lng_array(1,1) = 3 lng_array(2,1) =
100lng_array(1,2) = 4 lng_array(2,2) = 98lng_array(1,3) = 56
lng_array(2,3) = 55lng_array(1,4) = 78 lng_array(2,4) = 77
Double arrays
DOUBLE dbl_array(5)
String arrays
The declaration of string arrays differs from that for other array
type in that the first dimension contains the length of the strings
to be stored in the array. For example:
STRING strg(26)
strg = "good morning" The words "good morning" are stored from the
first position of strg:"good morning"
strg(1) = "good morning" The same result but filled with spaces:
"good morning "
strg(9) = "good morning" The string is stored from position 9
onwards and filled with spaces:" good morning "
strg(2;3) = "Hello" The letters "Hel" (3 characters) are stored
from position 2 onwards: " Hel good morning "
Example 3 (accessing string variables)
Suppose the string declared in the previous example has the value
"ABCDEFGHIJKLMNOPQRSTUVWXYZ". The results of the statements below
will be as indicated:
STRING twice(6,2)
There are two lengths associated with a string: the maximum and the
current length. The maximum length is defined at declaration of the
string and the current length can vary, depending on the contents of
the string.
If a string is declared as STRING strg(100), the maximum length of
strg is 100. If strg is filled as strg = "hello", the current length
is 5. If strg is filled as strg(1) = "hello", the current length is
also is 100, as the remaining positions are filled with spaces. When
you specify a start position, the string is always filled out with
spaces.
Related topics
§ Variables