Initializing ARRAYs and STRUCTs
The initialization of user-defined data types can easily be done using the 'Init Value Configuration' editor which is a subeditor of the variables table. The editor can be used for all user-defined data types (arrays, structures, enumerations and strings) but particularly for arrays and structures with a large number of elements/members.
- Open the 'Init Value Configuration' editor by selecting the context menu item 'Show Init Value Configuration' of a variable declaration in the variables table or by clicking the corresponding icon on the variables table toolbar:
The subeditor is opened below the variables table.
- In the variables table, select the user-defined data type to be initialized. Its elements/members are listed in the 'Init Value Configuration' editor.
Note
If several declarations are selected in the table, the editor appears empty.In case of arrays of structures, the individual structures can be expanded and collapsed:
- Depending on the number of elements/members,
- either enter the initialization value for each element/member into the corresponding input field in the right column,
- or initialize several elements/members by entering a group initialization statement into the input field above the grid. See the following section for details.
Note
If an initial value is read-only, it also appears write-protected in the editor and cannot be initialized.
Group initialization statements according to IEC 61131-3
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:
You can enter this initialization statement into the text field of the 'Init Value Configuration' editor above the grid.
Note
In the 'Init Value Configuration' editor, the following applies:
|
For the example shown above, the members are initialized in the grid below:
In the same way, combinations of arrays and structures can be initialized in the editor:
Example 1: Structure with array
In the following example, the structure MyStruct contains among other elements an array of Integers.
In the 'Init Value Configuration' editor, an initialization statement may be as follows:
Example 2: Array of structures
In the following example, an array of MyStruct is declared in the data types worksheet:
In the 'Init Value Configuration' editor, the initialization string contains repetition numbers not only for the array within MyStruct but also for the array of the structure:
Explanation of the initialization statement:
[
4((Field1 := 1, Field2 := TRUE, Field3 := [10(4)])),//4 elements are initialized
2( ), //next 2 elements with default init value
4((Field1 := 9, Field2 := TRUE, Field3 := [5(3), 5 (6)])) //last 4 elements are initialized
]