Declaring an array

A programming object (POU or GVL) of a project is open.
1. Select the Auto Declare command in the Edit menu or in the context menu of the editor.
The Auto Declare dialog opens.
2. Select the required scope for the array from the Scope selection list.
3. Enter an identifier for the array in the Name input field.
4. Click on Declaring an array 1: next to the Type input field and select the entry Array Wizard from the selection menu.
5. Enter the lower and the upper index bounds for the first dimension of the array in the Dimension 1 input fields, for example: 1 and 3.
The Result field shows the 1st dimension of the array, for example: ARRAY [1..3] OF ?.
6. In the input field Base Type enter the data type of the array, either directly or via the Input Assistant or the Array Wizard (button Declaring an array 2:), for example: DINT.
The Result field shows the data type of the array, for example: ARRAY [1..3] OF DINT.
7. Define dimensions 2 and 3 of the array according to steps 5 and 6, for example: dimension 2: 1 and 4, dimension 3: 1 and 2.
The Result field shows the array with the defined dimensions: Array [1..3, 1..4, 1..2] OF DINT. The array consists of 3 * 4 * 2 = 24 elements.
Declaring an array 3:

For a variable length array, declare the dimension bounds with the asterisk placeholder *. Arrays of variable length are only allowed in VAR_IN_OUT declarations of function blocks, methods or functions.

Example for a two-dimensional array of variable length: aVariableLength : ARRAY [ * , * ] OF INT;

8. Click OK.
In the Auto Declare dialog, the Type field shows the array.
9. To change the initialization values of the array, click Declaring an array 4: next to the Initialization Value input field.
The Initialization Value dialog opens.
10. Select the row of the array element, whose initialization value you want to change. Example: select array element [1, 1, 1].
11. Enter the required initialization value in the input field below the list and click on Apply value to selected lines, for example: "Value 4".
TwinCAT shows the modified initialization value for the selected row.
12. Click OK.
TwinCAT shows the initialization values of the array in the Initialization field of the Auto Declare dialog, for example: [4, 23(0)].
13. If required, you can enter a comment in the input field (optional).
14. Click OK to complete the array declaration.
TwinCAT adds the array declaration to the declaration part of the programming object.

See also: