Assignment Statement and Operator

<< Click to Display Table of Contents >>

Navigation:  Project > Scripts > ST language > Operators and Expressions in STL > Operators and Statements >

Assignment Statement and Operator

Previous pageReturn to chapter overviewNext page

There are several statements available in Structured Text. All of them represent an action or a condition. Beginning with actions, the most fundamental statement in Structured Text is the assignment statement. Here’s how an assignment statement looks like:

A = B;

What does this statement tell the compiler to do? To take the value of the variable B and put it in the variable A. The TeslaSCADA2 is assigning a value to a variable. Here’s an even simpler example:

A = 10;

This statement will take the value 10 and put it into the variable A. Or said in another way – the variable A will be assigned the value 10.Since the value of A is now 10, we can make another statement, but this time with an expression:

B = A + 2;

When this line of code is compiled, the expression A + 2 will be evaluated to 12. The compiler will replace the expression with the result 12. The statement will now look like this to the compiler:

B = 12;

What will happen now, is that the compiler will assign the value 12 to the variable B. The last thing is that the = symbol is called the assignment operator. You can have all sorts of expressions in your assignment statements, from simple values like numbers to variables and functions. Because all expressions will be evaluated first, and then, the result of that evaluation will be used in the assignment statement.