-

Declaring Variables/FB Instances

This topic contains the following sections:

Where can you declare variables/FB instances

Variables and FB instances can be created and declared as follows:

Note
All modifications on variable properties in one of the variables tables are immediately applied to all other variables tables where the corresponding variable is listed.

Further Info
For detailed information on the 'Variables' and Data Lists, refer to the topic "Managing Declarations in Tables".

Declaring variables/FB instances in a variables table or Data List

  1. To open the local variables table of the a POU, double-click the POU icon in the COMPONENTS area and activate the 'Variables' editor in the editor group.

    To open the Data List...

    • of the standard (non-safety-related) controller, double-click the 'IEC 61131-3' node in the PLANT.
    • of the Safety PLC, double-click the 'Safety PLC' node.

    Then, activate the Data List editor in the editor group.

  2. In the table, select a line above which the new variable is to be inserted and use the 'Create Variable' button on the toolbar or the 'Create Variable' command from the context menu. Alternatively, go to the end of the table, left-click into the empty 'Enter ... here' input field and enter the name of the new variable.
    In the variables table, clicking the arrow down icon on the right of the input field provides the list of all global variables that are not referenced in the current code worksheet so far.

    The new variable is added with default properties.

  3. Set the variable properties (data type, usage, initial value, various flags, etc.) in the variables table.
    In case of an FB instance, enter a valid instance name into the 'Name' field and select a function block in the 'Type' field.
    When working with a PLCnext Technology controller, IN and OUT ports can be declared in program POUs.

Declaring variables/FB instances while editing code

Instead of first adding a variable/instance declaration to the variables table, and then inserting the relating variable or instance into a code worksheet, you can declare variables/instances directly on insertion into the code.

Note
IN and OUT ports for PLCnext Technology controllers cannot be created this way. Instead, you have to declare the port in the variables table and then insert the declared port into the code.

To open a code worksheet of a POU, double-click the respective POU icon in the folder 'COMPONENTS | Programming > Local > Functions & Function Blocks' or 'Programs' (or any subfolder).

Declaring a variable while editing ST

Declaring a variable while editing FBD/LD, NOLD, and SNOLD