Вы находитесь на странице: 1из 6

CHAPTER 2

Variable Operators
Cicode is used to manipulate data and perform tasks. Data manipulation is achieved
using five classes of operators. These are the Mathematical, Bit, Logical, Relational
and Format operators.
In this chapter we will learn how to use the operators in each of the different classes.

Chapter Objectives
In this chapter you will learn:

About the classes of operators in Citect

The order of precedence of operators

2-2

Cicode Training Manual

Classes of Operators
The following describes the five classes of operators available in Citect.

Mathematical Operators
The standard mathematical operators used to perform calculations on numeric
variables such as integers and floating point numbers. The available mathematical
operators are:

Operator

Description

Addition (for numeric value)

Concatenation (for string variables)

Subtraction

Multiplication

Division

MOD

Modulus (Remainder)

As an example of the MOD operator , if we executed the following command:

TAG_1 = TAG_2 MOD 100

Then if TAG_2 is 101, then TAG_1 becomes equal to 1 (the remainder after TAG_2 is
divided by 100).
An example of the concatenation operator is below:

Only a string is allowed to be passed to the Prompt() function and one way that the
value of TAG_1 can be displayed is to use concatenation. Note that since the data
type of TAG_1 is an integer we need to convert its type to a string before we can use
it. Hence the use of the function IntToStr().

Variable Operators

2-3

Logical Operators
Logical operators can be used to test the logical state of an operand. The return
result after the test can only be TRUE (1) or FALSE (0). The three logical operators
are:

Operator

Description

AND

Logical AND

OR

Logical OR

NOT

Logical NOT

Bit Operators
Standard bit operators are provided with Cicode. These are:

Operator

Description

BITAND

Bitwise AND

BITOR

Bitwise OR

BITXOR

Exclusive OR

The bit operators can be used on words or individual bits.

Eg1.

11011 AND 1101 becomes 01001.

2-4

Cicode Training Manual

Relational Operators
To test the relationship between two values, the relational operators can be used.
Operator

Description

Is EQUAL to

<>

Is NOT Equal to

<

Is LESS than

>

Is GREATER than

<=

Is LESS than or Equal to

>=

Is GREATER than or Equal to

Format Operator
The format operator is used to convert numeric values into formatted strings for
display purposes.

Operator

Description

: (colon)

String Format

For example, to convert a numeric value to a string we would have:

TAG_1 : ####.#

In this example, TAG_1 will be displayed as four digits before and one digit after the
decimal point. This type of formatting can be used when displaying a number as a
string. We commonly use this in report format files.

Variable Operators

2-5

Order of Precedence of Operators


In Cicode each operator has been assigned a precedence. This means that an operator
of higher precedence will execute before operators of lower precedence. The
precedence of operators from highest to lowest is:

1.

()

2.

NOT

3.

*, /, MOD

4.

5.

+, -

6.

<, >, < =, > =

7.

=, < >

8.

AND

9.

OR

10.

BITAND, BITOR, BITXOR

For example, if we have the expression:

TAG_1 OR TAG_2 AND NOT TAG_3

the NOT TAG_3 is evaluated first, which is logically ANDed with TAG_2, the result of
which is logically ORed with TAG_1. This is equivalent to:

(TAG_1 OR (TAG_2 AND (NOT TAG_3)))

NOTE: Having the brackets shows more clearly the order of precedence that will be taken.

2-6

Cicode Training Manual

Exercise 2-1
Go to the page YourProgs and create a button called Statement to perform the
logical expression:

Cheese_Valve = Ham_Valve AND NOT Pine_Valve