Operators

<< Click to Display Table of Contents >>

Operators

SoftMaker Basic supports the following operators:

Arithmetic operators

Operator

Function

Example

+

Addition

x = a + b

-

Subtraction

x = a - b

 

also: Negation

x = -a

*

Multiplication

x = a * 3

/

Division

x = a / b

Mod

Modulo

x = a Mod b%

^

Exponentiation

x = a ^ b

String operators

Operator

Function

Example

+

Concatenation

x = "Good " + "Day"

&

Concatenation

x = "Good " & "Day"

The difference between the operators + and & is in the handling of variant variables that contain numbers: the + operator adds these numbers, whereas the & operator concatenates them as strings (see example).

Example:

Sub Main

 Dim a, b as Variant      ' 2 variant variables

 a = 2

 b = 3

 Print a + b              ' Return the number 5

 Print a & b              ' Returns the string "23"

End Sub

Comparison operators

Operator

Function

Example

<

Less than

If x < y Then ...

<=

Less than or equal to

If x <= y Then ...

=

Equal to

If x = y Then ...

>=

Greater than or equal to

If x >= y Then ...

>

Greater than

If x > y Then ...

<>

Not equal to

If x <> y Then ...

The result of comparisons with these operators is an Integer value:

-1 (True) if the condition applies

0 (False) if the condition does not apply

Logical and bitwise operators

Operator

Function

Example

Not

Logical negation

If Not (x = a) Then ...

And

Logical and

If (x > a) And (x < b) Then ...

Or

Logical or

If (x = y) Or (x = z) Then ...

These operators work bitwise. This means that you can use them for logic testing as well as for bitwise operations.

Precedence of operators

Operators are processed in the following order:

Operator

Function

Precedence

( )

Parentheses

highest

^

Exponentiation

 

+ -

Positive/negative sign

 

/ *

Division/multiplication

 

+ -

Addition/subtraction

 

Mod

Modulo

 

= <> > < <= >=

Comparison operators

 

Not

Logical negation

 

And

Logical and

 

Or

Logical or

lowest