Navigation:  thinBasic language > Operators >

Assignment operators

Previous pageReturn to chapter overviewNext page

 

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

 

but thinBasic support also some pre-assignment operators very useful in many cases. 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 variable value to right expression before assigning result back to variable

Counter += Idx

Counter = Counter + Idx

-=

Subtract variable value to right expression 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"

 

 

© 2004-2008 thinBasic. All rights reserved. Version 1.7.0.0 Web Site: http://www.thinbasic.com