+ (operator)

Syntax expression1 + expression2
Description Adds or concatenates two expressions.
Comments Addition operates differently depending on the type of the two expressions:
If one  expression is and the other  expression is   then
Numeric Numeric Perform a numeric add (see below).
String String Concatenate, returning a string.
Numeric String A runtime error is generated.
Variant String Concatenate, returning a String variant.
Variant Numeric Perform a variant add (see below).
Empty variant Empty variant Return an Integer variant, value 0 .
Empty variant Boolean variant Return an Integer variant (value 0 or -1 )
Empty variant Any data type Return the non- Empty expression unchanged.
Null variant Any data type Return Null .
Variant Variant If either is numeric, add; otherwise, concatenate.
When using + to concatenate two variants, the result depends on the types of each variant at runtime. You can remove any ambiguity by using the & operator. Numeric Add A numeric add is performed when both expressions are numeric (i.e., not variant or string). The result is the same type as the most precise expression, with the following exceptions:.
If one expression is and the other expression is   then
Single Long Double
Boolean Boolean Integer
A runtime error is generated if the result overflows its legal range Variant Add If both expressions are variants, or one expression is numeric and the other expression is Variant , then a variant add is performed. The rules for variant add are the same as those for normal numeric add, with the following exceptions:
  • If the type of the result is an Integer variant that overflows, then the result is a Long variant.
  • If the type of the result is a Long , Single , or Date variant that overflows, then the result is a Double variant.
Example This example assigns string and numeric variable values and then uses the + operator to concatenate the strings and form the sums of numeric variables.
Sub Main()
  i$ = "concatenate " + "strings!"
  j% = 95 + 5     'Addition of numeric literals
  k# = j% + j%    'Addition of numeric variable
  MsgBox "You can " + i$
  MsgBox "You can add literals or variables:" + Str(j%) + ", " + Str(k#)
End Sub
See Also & (Operator); Operator Precedence (topic)