Variable Arrays

Variable arrays do not need to be declared. Variable arrays come into existence via the assign statement when the expression on the right hand side of the assign statement evaluates to an array or when the left hand side of the assign statement refers to an element in a variable array.

ASSIGN/V1=Array(3,4,5,6,7)
Creates 5 element array and assigns it to V1.

ASSIGN/V2=V1[3]
Assigns V2 the value of the third element in array V1: 5.

ASSIGN/V1[4]=23
Assigns 4th element of array V1 to 23.

Arrays are created and allocated dynamically. Thus an array can be created by using an array reference on the left hand side of an assign statement.

ASSIGN/V3[5]=8
Dynamically creates array with 5th element set equal to 8.

When referencing an array element that has never received a value, the array expression will evaluate to 0.

ASSIGN/V3[5]=8

ASSIGN/V4=V3[5]
V4 is set equal to the value 8.

ASSIGN/V5=V3[6]
If the sixth element of V3 has never been set, V5 is set equal to 0.

Like other array types, expressions can be used within the square brackets.

ASSIGN/V3[5]=8

ASSIGN/V4=V3[2+3]
V4 is set equal to the value 8.

Variable arrays can have multiple dimensions.

ASSIGN/V6=Array(Array(4,7,2),Array(9,2,6))
V6 is set to a 2 by 3 dimensional array where V6[1, 1] equals 4, V6[1, 2] equals 7, V6[1, 3] equals 2, V6[2, 1] equals 9, V6[2,2] equals 2, and V6[2,3] equals 6.

ASSIGN/V7=V6[2,1]
V7 is set to the value 9.

Variable arrays can have negative indexes:

ASSIGN/V8[-3]=5
The –3rd index of array V8 is set to 5.

Array assignment will overwrite previous values:

ASSIGN/V8="Hello"
The variable V8 is equal to the string "Hello"

ASSIGN/V8[2]=5
V8 is no longer of type string, but of type array, the second element of which has a value of 5.

ASSIGN/V8=9
V8 is no longer an array, but an integer of value 9.

Arrays can be made up of multiple types:

ASSIGN/V9=Array("Hello",3,2.9,{FEAT1})
Creates array V9 with four elements. The first element is a string, the second element is an integer, the third element is a real number, and the fourth element is a pointer to FEAT1.

Arrays can be increased in size to include more elements:

ASSIGN/V10=ARRAY(3,1,5)

ASSIGN/V10[LEN(V1)+1]=7
The first statement creates an initial array V10 with three elements (3,1, and 5). The second statement then grows the array in V10 by one element and gives the final element a value of 7.