Command Auto Declare
Function: The command opens the Auto Declare dialog, which supports the declaration of a variable.
Call: Edit menu; Editor window context menu
Requirement: A POU is open in the editor and the cursor is in a program line.
The auto-declaration function opens the Auto Declare dialog even if the cursor is in the implementation part of a POU in a line that contains the name of an undeclared variable. To do this, you must have activated the option Declare unknown variables automatically (AutoDeclare) in the TwinCAT options (Extras > Options > TwinCAT > PLC Programming Environment > Smart Coding).
Due to the smart tag feature, the command Auto Declare also appears if you place the cursor on a variable that has not been declared in the implementation part of the ST editor and then click (available from build 4026).
Auto Declare dialog
Scope | Validity range of the variables that have not yet been declared. Example: |
Name | Variable name not yet declared Example: |
Data type | : Lists the standard data types. :
Example: |
Object | Object in which the new variable is declared. By default, this is the object you are editing. : Lists the objects in which the variable can be declared. If no objects are available for the selected scope, the entry <Create object> appears. If you select the entry <Create object>, the dialog Add object opens, which can be used to create a suitable object. |
Initialization value | If you do not enter an initialization value, the variable is initialized automatically. : Opens the Initialization dialog. This approach is helpful for initializing structured variables. Example: |
Address | Memory address (see PLC documentation: Addresses) Example: %IX1.0 |
Flags | Attribute keywords
The selected attribute keyword is added to the variable declaration. |
Comment | The tabular declaration editor displays the comment that was entered in the Comment column. In the textual declaration editor, it is displayed above the variable declaration. Example: |
Apply changes using refactoring | This option appears for the following validity ranges:
This option is automatically enabled if the autodeclaration options On renaming variables and On adding or removing variables, or on changing the scope are enabled in the TwinCAT options (Tools > Options > TwinCAT > PLC Environment > Refactoring) (see Dialog Options - Refactoring). If this option is enabled, the variable is not yet declared when the dialog is closed. Instead, the Refactoring dialog opens, in which you can edit the changes further. |
OK | The variable is declared and appears in the declaration. Example:
|
See also:
- PLC documentation: Declaring variables
Array dialog
Ranks and base type specification | Definition of the field sizes (dimension) by entering the lower and upper bounds and the base type of the array. You can enter the base type directly or by using the Input Assistant or Array dialog, if you click the button. |
Result | Display of the defined array. |
TwinCAT only reinitializes variables if you have changed the initialization values of the variables. |
Initialization Value dialog
Listing of the variables with name (expression), initialization value and data type. Changed initialization values are shown in bold. | |
Input field below the list | Enter an initialization value for the selected variable(s). |
Apply value to selected lines | Change the initialization value of the selected line(s) according to the value of the input field. |
Reset selected lines to default values | Setting the default initialization values. |
OK | TwinCAT adopts the initialization values in the Auto Declare dialog. |
If the variable to be initialized via this dialog is a function block instance with extended FB_Init method, another table is displayed above the Initialization value table (see PLC documentation: Methods FB_init, FB_reinit and FB_exit). This table lists the additional FB_Init parameters. The meaning and operation is basically the same as the table below with the following differences:
- All variables must be assigned initialization values. Otherwise OK is not selectable.
- For complex data types (structures, arrays) no components contained in them are displayed (type cannot be expanded). In this case, the complex type must be initialized with a corresponding variable.
For FB_Init parameters configured in this way, a corresponding symbol is displayed behind the initialization value in the Auto Declare dialog.
See also:
- PLC documentation: Using the input wizard