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:
Register - specified by its tag name
Register - specified by an address
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
In a User Program, choose the Expression (113) command, and double-click the Expression box. The Expression Editor will open.
Enter the first register and the assignment operator. Note that the Expression must begin with "[register] := ".
To enter the first part of the expression:
In the Tags box, find the desired register and double click it. It will be placed in Expression box. Then, in the Operators box, double-click the assignment operator (:=). It will also be placed in Expression box.
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.
Complete the expression:
Double-click any item in the lists on the Tags, Functions or Operators tabs to insert into the expression.
Type other items, such as register addresses or numeric values.
To mix data types, you must explicitly convert them. For example, you cannot directly assign a fractional value to an integer variable. You must use the data type conversion functions.
If you enter multiple expressions in the Expression command, each expression must end with a semi-colon. See the examples above.
If the expression is invalid, the Expression Builder give an error. When no errors are listed, the expression is valid.
Click OK to close the dialog and enter the expression in the command.
See Also
Expressions Overview | Constants | Functions | Operators | If Statement | Keywords
Copyright © 2024 Delta Computer Systems, Inc. dba Delta Motion