Operator (+)
|
<< Click to Display Table of Contents >> Navigation: ThinBASIC Core Language > Operators > Arithmetic > Operator (+) |
Description
Used to sum two numbers or concatenate two strings.
Syntax
result = expression1 + expression2
The + operator syntax has these parts:
| Part | Description |
| result | Any variable. |
| expression1 | Any expression. |
| expression2 | Any expression. |
Returns
N/A
Remarks
Although you can also use the + operator to concatenate two character strings, you should use the & operator for concatenation to eliminate ambiguity and provide self-documenting code.
When you use the + operator, addition or string concatenation will occur based on result type:
| If | Then |
| Result is numeric | Add |
| Result is string | Concatenate |
Restrictions
See also
Examples
DIM MyString AS STRING
DIM MyNumber AS LONG
'Results will be the string '123'
MyString = 1 + 2 + 3
MyString = 1 & 2 & 3
'Result will be the number 6
MyNumber = 1 + 2 + 3