Declaring Global Variables

Declaring global variables that are available within the application.

Requirement: A project is open.

  1. In the Device tree of your project, select the application in which the global variables are to be valid.

  2. Select the context menu command Add object ‣ Global Variable List.

    CODESYS inserts the GVL in the Device tree under the application and opens it in the editor.

  3. Select the menu command Edit ‣ Auto Declare.

    The dialog box Auto Declare opens.

  4. In the selection list Scope, select the entry VAR_GLOBAL.

  5. In the field Name, enter a name for the global variable.

  6. Select a data type from the selection list Type.

  7. If your variable is to have an initialization value other than the standard initialization value, click on 863a1822005ba31dc0a8640e004a22fb_21d51bd0cd4519c1c0a8640e00abb4b7 next to the field Initialization.

    The dialog box Initialization Value opens.

  8. Double-click on the cell Init value of your variable and enter the desired valid value.

  9. Click on OK.

    The initialization value is displayed in the dialog box Auto Declare.

  10. Activate one of the Flags if necessary.

  11. Confirm your entries by clicking on the button OK.

    CODESYS inserts the declared variable in the GVL.

    The global variable is available in the total application of your project.

Declaring global variables that are available in the entire project.

  1. Select the menu command View ‣ POUs.

    The POUs view opens.

  2. In the POUs view, select the uppermost node with the project name and select the context menu command Add object ‣ Global Variable List.

    CODESYS inserts the GVL in the POUs view and opens it in the editor.

  3. Select the menu command Edit ‣ Auto Declare.

    The dialog box Auto Declare opens.

  4. In the selection list Scope, select the entry VAR_GLOBAL.

  5. In the field Name, enter a name for the global variable.

  6. Select a data type from the selection list Type.

  7. If your variable is to have an initialization value other than the standard initialization value, enter it in the column Initialization.

  8. Activate one of the Flags if necessary.

  9. Confirm your entries by clicking on the button OK.

    CODESYS inserts the declared variable in the GVL.

    The global variable is now available in the entire project.

See also