Assignment Statement

Help Contents

Introduction

The IEC 61131-3 ST assignment statement assigns the value of an expression to a variable. The assignment statement uses this syntax:

variable-reference := expression;

The assignment target, variable-reference, can be any writable Variable Reference. The source of the assignment, expression, can be any Expression that is compatible with the assignment target.

Examples

  1. Assignment of a constant to a variable:
    A := 12.5;
  2. Assign a value to an element of an Array:
    C[0] := -12;
  3. Assign members of a Struct:
    Position.Angle := ATAN2( Y, X );
    Position.Distance = SQRT( X * X + Y * Y );
  4. Assign one Struct to another:
    PreviousPosition := Position

The above examples use the following Variable Declarations:

TYPE
    PolarCoordinates : STRUCT
        Angle : LREAL;
        Distance : LREAL;
    End_STRUCT
End_TYPE
VAR
    A : LREAL;
    X, Y : LREAL;
    C : ARRAY [0..5] OF INT;
    NewPosition, PreviousPosition : PolarCoordinates;
End_VAR

Further Information

Structured Text

For other Structured Text (ST) statement types.

Variable Reference

To learn about variable references that can be used on the left of the := assignment operator.

Expressions

To learn about expressions that can be used on the right of the := assignment operator.

Glossary

For the meaning of terms used in Fernhill SCADA.