Combinations of user-defined Data Types
User-defined data types cannot only be nested (without recursive calls) but also be combined.
Use the 'Init Value Configuration' editor for initializing structures and arrays.
Arrays of structures
The use of array of structures, i.e., structures arranged as arrays, is shown in the following example.
Here, a production line ('line' array) with 6 drilling machines ('machine' struct) is reflected. Via the array index, each particular station can be accessed. Via the structure components, the different values for drilling can be assigned.
Structures with arrays, enums or strings
It is possible to use arrays, enumerations and strings in structures, i.e., one or more declared user-defined data types are contained as components in a structure. In the following example, an array ('seq') is contained in the structure as well as the 'material' enumeration, which can be set to one of the values 'wood', 'aluminum' or 'stone'.
Initializing combinations of arrays and structures
Combinations of structures and arrays, or to be more precise, their individual members/elements, can also be initialized using so-called repetition numbers.
Further Info
Refer to the topic "Initializing ARRAYs and STRUCTUREs" for information on the 'Init Value Configuration' editor mentioned below. |
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
]