Declaring an array

Requirement: A programming object (POU or GVL) of a project is open.

  1. Click Edit ‣ Declare variable.

    The dialog box Declare variable opens.

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

  3. Enter an array name in the input field Name.

  4. Click the arrow button ( b6d4eacad6cf6e02c0a8640e01cf5283_2514dabdcd1da22ac0a8640e017603ee ) 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 limits 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 Input assistant ( b6d4eacad6cf6e02c0a8640e01cf5283_2514dabdcd1da22ac0a8640e017603ee ) or the Array assistant (example: DINT).

    The field Result displays 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 field Result displays the array with the defined dimensions: Array [1..3, 1..4, 1..2] OF DINT.

    Note

    You can define an array of variable length with [\*|, \*|, \*]. Example: ARRAY [\*, \*] for a two-dimensional array of variable length. Arrays of variable length can be used only in VAR_IN_OUT declarations of function blocks, methods, and functions.

  8. Click OK.

    In the dialog box Declare variable the field Data type displays the defined array.

  9. To modify the initialization values of the array, click the arrow button ( b6d4eacad6cf6e02c0a8640e01cf5283_21d51bd0cd4519c1c0a8640e00abb4b7 ) next to the Initialization value input field.

    The dialog box Initialization value opens.

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

  11. Enter the desired initialization value in the input field below the list and click on the 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 Declare variable dialog box, CODESYS displays the initialization values of the array (example:{4, 23(0)]).

  13. You can optionally enter a comment in the input field.

  14. Click on 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.

See also