Command 'Auto Declare'Permalink

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 _cds_icon_light_bulb.

Dialog 'Auto Declare'

“Scope”

Scope of the variable that is not declared yet.

Example: ‎VAR‎ (default setting for local variables)

“Name”

Variable name not declared yet

Example: ‎bIsValid‎

“Type”

Example: ‎BOOL‎

  • _cds_icon_arrow_down: Lists the standard data types.

  • _icon_arrow_button

    • “Input Assistant”: Opens the “Input Assistant” dialog

    • “Array Assistant”: Opens the “Array” dialog

“Object”

Object where the new variable is declared. By default, the object that you are editing now.

Example: ‎fbA‎

_cds_icon_arrow_down: Lists that objects where the variable can be declared.

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: ‎FALSE‎

If you do not specify an initialization value, then the variable is initialized automatically.

_cds_icon_input_assistent: Opens the “Initialization Value” dialog. This procedure is helpful for the initialization of structured variables.

“Address”

Memory address of the application for the variable that is not declared yet.

Example: ‎%IX1.0‎

Note:

Possible only for the following scopes:

  • Local variable (‎VAR‎)

  • Global variable (‎VAR_GLOBAL‎)

  • Or for a persistent variable (‎PERSISTENT‎).

“Flags”

Attribute keywords

  • ‎CONSTANT‎: Keyword for a constant.

  • ‎RETAIN‎: Keyword for a remanent variable.

  • ‎PERSISTENT‎: Keyword for a persistent variable (stricter than ‎RETAIN‎).

The selected attribute keyword is added to the variable declaration.

“Comment”

Example: ‎New input In1‎

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”

_cds_icon_option_activated: When you exit the dialog, the variable is not declared yet, but then it opens the “Refactoring” dialog. You can continue editing your changes here.

The option appears for the following scopes:

  • Input variable (‎VAR_INPUT‎)

  • Output variable (‎VAR_OUTPUT‎)

  • ‎VAR_IN_OUT‎ variables (input variable and output variable)

“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 _icon_arrow_button button.

“Result”

Display of the defined array

NOTICE

NOTICE
NOTICE
NOTICE

NOTICE

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.