Arrays
An array is data structure that stores a collection of individual values that are of the same data type.
The NetLinx language allows arrays of any of the Intrinsic Data Types, as well as arrays of user-defined structures and classes.
- If an initialization statement is included in the variable declaration, the array dimension is not required.
- If the array dimension is omitted, both the maximum and effective length is set to the length needed to hold the data contained in the initialization string.
Example
String expressions can be used initialization statements only if each byte is separated by a comma:
For multi-dimensional array types, the data pertaining to each dimension is delimited using braces, as shown below:
The = Operator can be used to assign a one dimensional array to another:
The one-dimensional arrays must match type. The size of each dimension of the destination array must be greater than or equal to the corresponding array being assigned; otherwise the contents of the array being assigned is truncated to fit into the destination array. If a type mismatch is detected the compiler will issue an appropriate warning.
The lengths of an array are determined by calling LENGTH_ARRAY and MAX_LENGTH_ARRAY:
- LENGTH_ARRAY returns the effective length of a dimension of an array: the length set implicitly through array initialization or explicitly through a call to SET_LENGTH_ARRAY.
- MAX_LENGTH_ARRAY is used to determine the maximum length of a dimension of an array.
Changing an element in array does not change its length. SET_LENGTH_ARRAY is used to change the effective length of an array when necessary, such as when you've added elements via a FOR loop:
Multi-dimension arrays cannot be copied directly to another. Use FOR or WHILE loops to copy them at the lowest dimension: