Addition Operator (+)

Sums two numbers.

Syntax

result = expression1 + expression2

Arguments:

  • Result: Any numeric variable.

  • expression1: Any expression.

  • expression2: Any expression.

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, you may not be able to determine whether addition or string concatenation will occur.

The underlying subtype of the expressions determines the behavior of the + operator in the following way:

  • If Both expressions are numeric, then Add.

  • If Both expressions are strings, then Concatenate.

If both expressions are Null or empty expressions, result is zero (0). However, if only one expression is Empty or Null, the other expression is returned unchanged as result.

The following examples illustrates the use of addition operator.

Example 1:


Dim num1, num2, result
num1 = 10
num2 = 5
result = num1 + num2
'Output -> 15