Addition operator (LotusScript® Language)

Finds the sum of two numbers.

Syntax

numExpr1 + numExpr2

Elements

numExpr1, numExpr2

Any numeric expressions. An EMPTY operand is considered a 0.

Return value

When adding expressions of numeric data types, the result is a value whose data type in most cases is the same as that of the operand whose data type is latest in this ordering: Integer, Long, Single, Double, Currency. For example, if one operand is a Double and the other is an Integer, then the data type of the result is Double.

The exceptions are:

  • When the resulting data type is a Variant of Integer that overflows its legal range, the result is converted to a Variant of Long.
  • If numExpr1 and numExpr2 are both EMPTY, the result has Integer.
  • When the resulting data type is a Variant of Long, Single, or Date/Time that overflows its legal range, the result is converted to a Variant of Double.

Usage

LotusScript® interprets the + operator as either addition or string concatenation, depending on the data types of expr1 and expr2. The following table lists these interpretations. The numeric data types are Integer, Long, Single, Double, Currency, and (in a Variant variable only) Date/Time.

One expression

Other expression

Operation

Numeric

Numeric

Addition

Numeric

String

(Type mismatch error occurs)

Numeric

Variant (other than NULL)

Addition

String

Variant (other than NULL)

String concatenation

String

String

String concatenation

Any type

Variant that contains EMPTY

Returns first expression

Any type

NULL

Returns NULL

Variant of numeric data type

Variant of numeric data type

Addition

Variant of numeric data type

Variant of String data type

Addition, if string can be converted to a numeric data type; otherwise a type mismatch error occurs

Variant of String data type

Variant of String data type

String concatenation

To avoid confusion, use the & operator, not the + operator, for string concatenation.

Example

Dim a As Variant
Dim b As Integer
a = "8"
b% = 7
' Use operator for addition.
Print 8 + 7                           ' Prints 15
Print a + 7                           ' Prints 15
Print 8 + b%                          ' Prints 15
Print a + b%                          ' Prints 15
' Use operator for string concatenation.
Print "Hello " + "there"              ' Prints "Hello there"
Print a + "7"                         ' Prints "87"