-

Assign variables/constants to an LD object

Each LD object must have a valid variable or constant assigned. In LD, the object name corresponds to the name of the variable/type of constant assigned to the object. On insertion of a contact or coil, a default name is assigned. As this new object is not yet declared in the local variables table or any Data List, the object is highlighted in the code worksheet and a corresponding error is reported.

A variable can be assigned to an LD object using the following methods.

Method 1: selecting a variable that is already declared in the local variables table

  1. Double-click the LD object in the code worksheet.
  2. In the appearing selection box, browse for the variable to be inserted (type the first character(s) of the variable to facilitate your search), select the variable and press <Enter>.

Method 2: assigning a variable by drag & drop

Drag the variable from the local variables table into the code worksheet and drop it on the desired LD object.

If an input variable is dragged from the variables table and directly dropped on an LD network rung (not on an object), it will be added as contact.

If an output variable is dragged and dropped on the LD network rung, a coil will be inserted.

Method 3: declaring a new variable for an LD object

  1. Double-click the LD object, enter the name of the new variable in the appearing selection box and press <Enter>.
  2. Right-click on the variable and select 'Create New Variable > Variable type' from the context menu, or left-click the variable and select the appropriate in-place button:

    local variable
    input variable in an FB POU
    output variable in an FB POU
    InOut variable in an FB POU

    InOut variables are not supported in safety-related POUs.
    external variable
    program-global variable in a program POU

    Program-global variables are not supported in safety-related POUs.

    See also topic "Variable Declaration Keywords" for details.

  3. If required, set the variable properties (data type, initial value, various flags, etc.) in the variables table.