Arrays
Arrays are declared in the data type worksheet using a TYPE...END_TYPE declaration block. The array may be multi-dimensional. Array data types consist of several elements of the same data type. Each element can be accessed via its unique element index.
The array length (number of elements or values the array can hold) can be defined using either literals (fixed values) or constant variables. Constant variables have to be declared as VAR CONSTANT in the data type worksheet using a VAR CONSTANT...END_VAR declaration block (see the example below).
Example: 1-dimensional array of 10 integers; array length defined using literals
Data type definition | ![]() |
Variable declaration ('Variables'/Data List) | ![]() |
Use in code | ![]() |
Example: 1-dimensional array of 10 integers; array length defined using constant variables
Data type definition | ![]() |
Variable declaration ('Variables'/Data List) | ![]() |
Use in code | ![]() |
Example: 2-dimensional array; declaration using an array of an already declared array
Data type definition | ![]() |
Variable declaration ('Variables'/Data List) | ![]() |
Use in code | ![]() |
Further Info
See also the topic "User-defined data types". |
Initializing arrays
Arrays, or to be more precise, the individual members contained in an array, can be initialized as follows:
For initializing arrays with a large number of values, so-called repetition numbers can be used.
Example of an initialization in a data types worksheet:
This initialization means the same as:
In the 'Init Value Configuration' editor, these repetition numbers can be entered as initialization statement to initialize arrays.
Note
If you are using PLCnext Engineer in another user interface language and/or with another Windows system locale than English you must enter numeric values with a '.' as decimal separator (always according to the English standard). This applies, for example, when entering initial values in variables tables or REAL/LREAL literals in the code. |