Language and Conventions Overview | Subrange Operator
Arrays are ordered lists of variables that can be addressed individually or as a group. One, two, or three dimensional arrays may be defined for numbers and objects. String arrays can be two dimensional.
An array is defined as a variable. The declarations (NUMBER, STRING, ENTITY) are used to create the arrays in a GRIP program. The array is then used later in the program for assigning values (either, objects, strings, or numerical values). Numerical variables do not need to be declared, however, a numerical array must be declared using the NUMBER declaration.
Arrays are written as the variable, then the size of the dimensions of the array in parentheses:
Variable(1st Dimension,2nd Dimension,3rd Dimension)
For example, if you wanted to declare a single dimensional object array for four lines, it could be declared as follows:
ENTITY/LN(4)
The last parameter of a STRING array is always the maximum number of characters in each string:
Variable(No. of Strings,Max No. Characters per String)
The following example would declare four strings of a maximum of twenty characters per string.
STRING/STR(4,20)
When you use the variable STR in you program, you only need to refer to the first position of the two dimensional array:
STR(1)='This is a string'
You can set numerical arrays equivalent to other numerical arrays of the same dimension and size. However, ENTITY and STRING arrays cannot be set equivalent to other arrays. For example:
NUMBER/A(5),B(5)
A=B
is valid.
STRING/ST1(3,20),ST2(3,20)
ST1=ST2
is invalid and will not compile.