Assignment Expressions

An assignment expression assigns a value to a register. Assignment expressions are used in the Expression (113) command in a User Program, and in User Functions.

Assignment Expression Basics

An assignment expression must follow this format:

Register := Expression;

where:

Register must be writable and may be any of the following:

The semicolon at the end is not required if the Expression command contains only one assignment.

Expression is a mathematical expression that must evaluate to a numeric value with the same data type as the Register.

Sample Expressions

Example 1

 

MyCounter := MyCounter +1;

 

Note: MyCounter must exist as a variable.

Example 2

 

MyVariable := 12.9 + SampleVariable2 / (3.0 + Axis[1].ActPrs);

 

Note: MyVariable and SampleVariable2 must exist as variables.

Example 3

 

F18:2 := 3.0 + ABS(Axis[].ActPos);

 

Example 4

 

IF_Axis[0].StatusBits.0 = TrueTHEN

MyREAL1 := 34.0;           

MyREAL2 := 70023.0;

ELSIFABS(_Axis[0].ActPos) > 20.0 THEN

%QX0.1 := True;

ELSE

MyDINT := 2;

END_IF

 

Note: MyReal1, MyReal2, and MyDINT must exist as variables.

Entering an Expression

  1. In a User Program, choose the Expression (113) command, and double-click the Expression box. The Expression Editor will open.

  2. Enter the first register and the assignment operator. Note that the Expression must begin with "[register] := ".
    To enter the first part of the expression:

Note:
You can also type the information directly in the Assignment Expression box.

Local Variables:
If your expression needs temporary variables, you can declare variables in the user program step. See Local Variables for details.

  1. Complete the expression:

  2. Click OK to close the dialog and enter the expression in the command.

 

See Also

Expressions Overview | Constants | Functions | Operators | If Statement | Keywords


Send comments on this topic.

Copyright © 2024 Delta Computer Systems, Inc. dba Delta Motion