Declaring Global Variables¶
Declaring global variables that are available within the application.
Requirement: A project is open.
In the Device tree of your project, select the application in which the global variables are to be valid.
Select the context menu command
.- ⇒
CODESYS inserts the GVL in the Device tree under the application and opens it in the editor.
Select the menu command
.- ⇒
The dialog box Auto Declare opens.
In the selection list Scope, select the entry VAR_GLOBAL.
In the field Name, enter a name for the global variable.
Select a data type from the selection list Type.
If your variable is to have an initialization value other than the standard initialization value, click on
next to the field Initialization.
- ⇒
The dialog box Initialization Value opens.
Double-click on the cell Init value of your variable and enter the desired valid value.
Click on OK.
- ⇒
The initialization value is displayed in the dialog box Auto Declare.
Activate one of the Flags if necessary.
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.
Select the menu command
.- ⇒
The POUs view opens.
In the POUs view, select the uppermost node with the project name and select the context menu command .
- ⇒
CODESYS inserts the GVL in the POUs view and opens it in the editor.
Select the menu command
.- ⇒
The dialog box Auto Declare opens.
In the selection list Scope, select the entry VAR_GLOBAL.
In the field Name, enter a name for the global variable.
Select a data type from the selection list Type.
If your variable is to have an initialization value other than the standard initialization value, enter it in the column Initialization.
Activate one of the Flags if necessary.
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