Operators

                   

Expand/Collapse all Show/Hide All

The following operators can be used:

Mathematical operators

String operators

 

Mathematical Operators

Use mathematical operators to perform numeric calculations. You can also include numeric literals by typing numeric characters within a numeric expression, usually separated by one or more operators. The following special characters are used to perform mathematical operations:

 

Expand/Collapse item  Table: Special Characters

Operator

Example

Result

Comment

+

100 + 200

300

Add two numbers

-

300 - 100

200

Subtract a number

*

5*20

100

Multiply two numbers

/

100/5

20

Divide two numbers

^

5^2

25

Raise to the power of

When evaluating a numeric expression, the operators are evaluated based on the following precedence: ^, * or /, + or -. If two operators of equal precedence occur, execution is performed from left to right.

Expand or collapse item Example

100 + 50 - 20 * 5 yields 50

In the example above, 20 and 5 are multiplied first and the result saved, then 100 and 50 are added together, and finally the saved value (100) is subtracted from 150, yielding 50.

Parentheses "( )" can be used to change the order of evaluation. Expressions within parentheses are evaluated first. Where parentheses are nested, the innermost parenthesized expression is evaluated first.

 

Expand or collapse item Example

100 + (50 - 20) * 5 yields 250

(100 + 50 - 20) * 5 yields 650

 

String Operators

Two operators can be used to combine string variables and reference substrings. In addition to using control variable names, you can use string literals enclosed in quotation marks in an expression. You can also create data values that contain specific ASCII characters by using hexadecimal digits (0-9, or A-F) enclosed by "$".

Expand or collapse item Example

"ABC" yields "ABC"

$414243$ yields "ABC"

$0D0A$ yields carriage return, line feed

 

Expand/Collapse item  Substrings

A substring consists of a portion of a string variable. Substrings are referenced by specifying the string variable followed by the starting character position within the string and, optionally, the length of the substring enclosed by parentheses "( )" operators.

Warning A substring must not exceed the current size of the string variable it references. If the length is exceeded, a null string ("") is returned.

If no length is specified, the substring consists of all characters from the starting position up to and including the last character within the string.

Example

If ML_NAME$ contained the string "ABCDEFGHIJK" then:

 ML_NAME$(1,1) yields "A"

 ML_NAME$(3,4) yields "CDEF"

 ML_NAME$(4) yields "DEFGHIJK"

Substrings can be used where a string variable is used, and as an argument to any string function.

 

Expand or collapse item String Concatenation

To combine two or more strings, the operator "+" is used. When two strings are concatenated, the resulting string consists of the contents of the string to the left of the "+" followed immediately by the contents of the string to the right of the "+." Any number of strings can be concatenated.

Example

If ML_NAME$ contained the string "ABCD":

 "Hello " + "there" yields "Hello there"

 ML_NAME$ + ".BMP" yields "ABCD.BMP"

 "My name is "+ML_NAME$ yields "My name is ABCD"

 "Hello " + ML_NAME$(1,2) yields "Hello AB"

 

Expand or collapse item  String Functions

A number of functions can be performed on string values only. Some common functions are NUM (converts strings to numbers), LEN (length of a string), and STP (strip spaces from a string).