ARRAY

Top  Previous  Next

An array is used to "group" a number of data elements together so that it can be referenced by an index.  

 

An array can also be initialized - the exception being arrays declared in VAR_INPUT / VAR_OUTPUT or in a FUNCTION.

In case an array is not fully initialized, the remaining elements in the array will simply be set to the default value 0 - FALSE by the compiler.

 

Only one-dimensional arrays are supported with a maximum number of elements defined by the execution architecture. Under X32/NX32 the maximum number of elements is 65535 and the maximum size of each element is also 65535.

Under the NX32L execution there is an unlimited number of elements with an unlimited size of each element.

 

The actual number and size of the defined arrays are only limited by the available memory.

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
  Input : ARRAY[1..8] OF BOOL; | The 8 input signals
END_VAR;
 
VAR_OUTPUT
  Output : ARRAY[1..8] OF BOOL; | The 8 output signals
END_VAR;
 
VAR
  index : SINT;
  work1 : ARRAY[2..5] OF INT := 123,678,345,678;
  work2 : ARRAY[1..5] OF STRING := "This", "Is", "a", "Big", "Test";
END_VAR;
 
PROGRAM test;
 
BEGIN
 
  // Copy each of the 8 inputs to the outputs
  FOR index:=1 TO 8 DO
     Output[index] := Input[index];
  END_FOR;
END;
 
END_PROGRAM;