1 calculation, Arithmetic operator, 2 comparison – KEYENCE SR-700 Series User Manual

Page 6: Comparative operator, 3 combination of condition, Logical operator, 4 character string concatenation, Concatenation operator, Calculation, Comparison

Advertising
background image

6

E SR SCRIPT RM

3-1

Calculation

This describes arithmetic operators used for general calculations.

Arithmetic operator

Format

On the left-hand side and the right-hand side of each operator, write an expression
using numerical values or variables of numerical values.

Important

If character strings are assigned to variables and they cannot be
converted to numerical values during calculation, an error will
occur on execution.

Reference

To obtain only the integer part of division result, use arithmetic function
math.floor.(Page 11)

3-2

Comparison

This describes comparative operators used when comparing numerical values or logical values.

Comparative operator

Format

On the left-hand side and the right-hand side of each operator, write numerical
values, variables of numerical values or arithmetic expression.

Important

Comparison is also possible by assigning character strings to
variables. However, when variables are evaluated by conditional
expression, and if they cannot be converted to numerical values,
an error will occur on execution.

Arithmetic

operator

Meaning

+

Addition

-

Subtraction

*

Multiplication

/

Division

%

Remainder (from division)

^

Power

Example

A = B

+

1

Assigns the result of variable B plus 1 to variable A.

Example

Comparative operator

Meaning

<

smaller

<=

smaller or equal

>

greater

>=

greater or equal

==

equal

~=

different

Example

Examples of calculations and results (a=5.5, b=2)

Arithmetic expression

Result

a

+

b

7.5

a

-

b

3.5

a

*

b

11

a

/

b

2.75

a

%

b

1.5

a

^

b

30.25

Examples of calculations and results (a=10, b=1)

Arithmetic expression

Result

a

>

b

true

a

<

b

false

a

==

10

true

a

~=

10

false

3-3

Combination of condition

This describes logical operators used when combining conditions.

Logical operator

Format

3-4

Character string
concatenation

This describes concatenation operators used to connect one character string to
another.

Concatenation operator

Format

Logical operator

Meaning

and

Logical AND operator: If the first argument is false or nil, the value is returned.

If not, the second argument is returned.

or

Logical OR operator: If the first argument is different from false or nil, the

first argument is returned. If not, the second
argument is returned.

not

Logical NOT operator: If the next value is false or nil, true is returned. If not,

false is returned.

Example

variable 1

..

variable 2

Expresses using 2 periods ".." between
variables.

Example

local a = "Keyence"

Declares variable a and initializes with character
string "Keyence".

local b = "Auto-ID"

Declares variable b and initializes with character
string "Auto-ID".

local c

Declares variable c.

c = a

..

b

Assigns values after a and b are connected.

Value of c: "KeyenceAuto-ID"

Examples of calculations and results

Arithmetic expression

Result

true

and

true

true

true

or

true

true

true

and

false

false

true

or

false

true

not

false

true

not

true

false

10

or

30

10

nil

or

30

30

false

or

nil

nil

Advertising
This manual is related to the following products: