Keyboard shortcut: [Shift]+[F2]
Function: The command opens the “Auto Declare” dialog, which supports the declaration of a variable.
Call: Menu bar: “Edit”
Requirement: An object or a device of the project is opened in the editor.
With the auto-declaration function, the “Auto Declare” dialog also appears when the cursor is located in the implementation part of a POU in a line containing the name of an undeclared variable. The requirement for this is that you must have clicked “Tools Options” and enabled the “Declare unknown variables automatically (AutoDeclare)” option in the “SmartCoding” category.
With the smart tag function, the “Auto Declare” command also appears when you place the cursor over an undeclared variable in the
implementation part of the ST editor and then click .
Dialog 'Auto Declare'
“Scope” |
Scope of the variable that is not declared yet. Example: |
“Name” |
Variable name not declared yet Example: |
“Type” |
Example:
|
“Object” |
Object where the new variable is declared. By default, the object that you are editing now. Example:
If no objects are available for the selected “Scope”, the entry “<create object>” appears. When you select the “<create object>” entry, the “Add Object” dialog opens for generating a suitable object. |
“Initialization” |
Example: If you do not specify an initialization value, then the variable is initialized automatically.
|
“Address” |
Memory address of the application for the variable that is not declared yet. Example: Note: Possible only for the following scopes:
|
“Flags” |
Attribute keywords
The selected attribute keyword is added to the variable declaration. |
“Comment” |
Example: In the tabular declaration editor, the comment entered is displayed in the “Comment” column, while in the textual declaration editor it is displayed above the variable declaration. |
“Apply changes using refactoring” |
The option appears for the following scopes:
|
“OK” |
The variable is declared and appears in the declaration. Example: VAR RETAIN // New input In1 xIn1 AT %IX1.0: BOOL := FALSE; END_VAR |
Dialog 'Array'
“Ranks and base type specification” |
Definition of the field sizes (“Dimension”) by entering the lower and upper limits and the “Base type” of the array. You can enter the basic type directly or with the help of the “Input Assistant” or “Array” dialogs when you click the |
“Result” |
Display of the defined array |




NOTICE

CODESYS reinitializes variables only if you have modified the initialization values of the variables.
Dialog 'Initialization Value'
List of the variables with name (“Expression”), “Initialization Value” and “Data Type”. Modified initialization values are displayed in bold fonts. |
|
Input field below the list |
Input of an initialization value for the selected variable(s) |
“Apply value to selected lines” |
Change of the initialization value of the selected line(s) according to the value of the input field |
“Reset selected lines to default values” |
Resets the default initialization values |
“OK” |
CODESYS applies the initialization values in the “Auto Declare” dialog. |
In the case that the variable to be initialized by means of this dialog is a function block instance with an extended FB_Init method, an additional table is displayed above the “Initialization Value” table. The additional FB_Init parameters are listed in this table. The meaning and operation essentially correspond to the lower table with the following differences:
-
All variables have to be assigned with initialization values. Otherwise “OK” remains disabled.
-
For complex data types (structures, arrays), no components contained within are displayed (type cannot be expanded). In this case, the complex type has to be initialized with a corresponding variable.
For FB_Init parameters configure this way, a corresponding symbol is displayed after the initialization value in the “Auto Declare” dialog.