Compound operators

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > Operators >

Compound operators

 

Assign values to Variables

 

Values are assigned to variables creating an expression as follows: the variable is on the left side of the expression and the value you want to assign to the variable is on the right.

 

For example:

 

Dim B As Long

B = 200

 

Usually equal sign (=) is used for variable assignment operation like:

 

Counter = Counter + 1

 

thinBasic support also some pre-assignment operators very useful in many cases. Such operators are also called compound operators

For example the previous example can be reduced to:

 

Counter += 1

 

In this case thinBasic sum 1 to the current value of Counter variable.

 

The following tables summarize all the supported assignment operators.

 

Numeric assignments

Method

Description

Example

Equal to

=

Assign right expression to a variable

Counter = Idx


+=

Add right expression to variable before assigning result back to variable

Counter += Idx

Counter = Counter + Idx

-=

Subtract right expression from variable before assigning result back to variable

Counter -= Idx

Counter = Counter - Idx

*=

Multiply variable value to right expression before assigning result back to variable

Counter *= Idx

Counter = Counter * Idx

/=

Divide (floating point version) variable by right expression before assigning result back to variable

Counter /= Idx

Counter = Counter / Idx

\=

Divide (integer version) variable by right expression before assigning result back to variable

Counter \= Idx

Counter = Counter \ Idx

 

String assignments

Method

Description

Example

Equal to

=

Assign right expression to a variable

MyString = "ABC"


+=

Add variable value to right expression before assigning result back to variable

MyString += "ABC"

MyString = MyString & "ABC"

&=

Add variable value to right expression before assigning result back to variable

MyString &= "ABC"

MyString = MyString & "ABC"

.=

Add variable value to right expression before assigning result back to variable

MyString .= "ABC"

MyString = MyString & "ABC"