2 string expressions – Rockwell Automation 57C610 Enhanced Basic Language, AutoMax User Manual

Page 35

Advertising
background image

5Ć3

BASIC evaluates expressions enclosed in parentheses before the

operator immediately outside the parentheses, even when the

operator enclosed in parentheses is on a lower precedence level

than the operator outside the parentheses. In the statement A = B*

(C - D), BASIC evaluates the (C - D) first, and then multiplies B by

the result of (C - D).
BASIC will still evaluate other expressions before those in

parentheses if the other expressions come first in the statement and

have a higher precedence. In the statement below, however, the

parenthetical expression occurs later in the overall expression. The

exponentiation operation is performed first (before the parentheses)

because it is encountered first in the leftĆtoĆright evaluation and, at

the time it is encountered, is a higher precedence than any operator

before it.
BASIC evaluates the expression A = B - C**5 + (X*(Z - 17)), in

the following sequence:

C%

Exponentiation

B - C%

Subtraction with first term

Z - 17

Innermost parenthetical expression

X * (Z - 17)

Next level of parentheses

[B - C%] + [X*(Z - 17)]

Combination of the two expressions

Arithmetic mixing of both single and double precision integers along

with real variables and constants is permitted in a BASIC statement.

The rules regarding truncation and the maximum size integerĆtoĆreal

conversion still apply.
The following are valid arithmetic mixing examples:

20 GAIN = MOTOR_SPEED%*(OLDGAIN!*13.8876)

or

20 GAIN! = GAIN! + REFERENCE%

The following example could cause an overflow if the resultant value

is larger than 16 bits of precision. In such a case, the largest

possible single positive or negative integer would be loaded into the

variable GAIN%. The program would continue to run, and an error

would be logged to notify the user of the problem.

20 GAIN% = REFERENCE! + GAIN%

5.2

String Expressions

BASIC provides three operations for use with string expressions.

These are the assignment operation (=), the concatenation

(addition of strings) operation (+), and the equality/inequality

comparison operations (=, < >, or > < ).
By using the assignment operator, you can equate or assign one

string variable or constant to another string variable. In the

statement below, the character sequence THIS IS A MESSAGE" is

assigned to the string variable C$:

C$ = THIS IS A MESSAGE"

The concatenation operator (+) combines string variables and

constants to form a new string expression:

C$ = HI" + B$ + D$ + STRING"

Advertising
This manual is related to the following products: