Skip to main content

Declaring Arrays

Requirement: A POU or GVL of a project is open.

  1. Click the Edit → Auto Declare command.

    The Auto Declare dialog opens.

  2. Select the desired scope for the array from the Scope list box.

  3. Specify an identifier for the array in the Name input field.

  4. Click the _icon_arrow_button.png button next to the Data Type input field and select the Array Assistant entry from the selection menu.

  5. In the input fields Dimension 1, type in the lower and upper limit of the first dimension of the array (example: 1 and 3).

    The field Result displays the 1st dimension of the array (example: ARRAY [1..3] OF ?).

  6. In the input field Basic type, type in the data type of the array or use the _icon_arrow_button.png Input Assistant or the Array Assistant (example: DINT).

    The Result field shows the data type of the array now (example: ARRAY [1..3] OF DINT).

  7. Define the second and third dimensions of the array according to steps 5 and 6 (example: Dimension 2: 1 and 4, Dimension 3: 1 and 2).

    The Result field displays the array with the defined dimensions: ARRAY [1..3, 1..4, 1..2] OF DINT. The array consists of 3 * 4 * 2 = 24 elements.

    Tip

    In an array of variable length, declare the dimension limits with an asterisk placeholder (*). Arrays of variable length are permitted to be used only in VAR_IN_OUT declarations of function blocks, methods, or functions.

    Example of a 2-dimensional array of variable length: aiUnknownLengthData : ARRAY [*,*] OF INT;

  8. Click OK.

    In the Auto Declare dialog, the Data Type field shows the array.

  9. To modify the initialization values of the array, click the _cds_icon_input_assistent.png button next to the Initialization value input field.

    The Initialization Value dialog opens.

  10. Select the line of the array element whose initialization value you want to modify. Example: Select array component [1, 1, 1].

  11. Specify the desired initialization value in the input field below the list and click button Use value on selected lines (example: value 4).

    CODESYS displays the changed initialization value of the selected line.

  12. Click OK.

    In the Initialization value field of the Auto Declare dialog, CODESYS displays the initialization values of the array (example:[4, 23(0)]).

  13. You specify an optional Comment in the input field.

  14. Click OK in order to conclude the declaration of the array.

    CODESYS adds the declaration of the array to the declaration part of the programming object.

For more information, see: data type ARRAY OF