


When you use the + operator, you may not be able to determine whether addition or string
concatenation is to occur. If at least one operand is not a Variant, the following rules apply.
+ Operator
| If
| Then
|
| Both expressions are numeric data types (Integer, Long, Single, Double, or
Currency)
| Add
|
| Both expressions are Strings
| Concatenate
|
| One expression is a numeric data type and the other is a Variant (other than a
Null)
| Add
|
| One expression is a String and the other is a Variant (other than a Null)
| Concatenate
|
| One expression is a String and the other is a Variant of VarType 8 (String)
| Concatenate
|
| One expression is a Variant containing Empty
| Return the remaining operand unchanged as result.
|
| One expression is a numeric data type and the other is a String
| A Type mismatch error occurs.
|
If both operands are Variant expressions, the VarType of the operands determines the behavior of the + operator in the following way.
| If
| Then
|
| Both Variant expressions are of VarType 2-7 (numeric data types)
| Add
|
| Both Variant expressions are of VarType 8 (String)
| Concatenate
|
| One Variant expression is of VarType 2-7 (a numeric data type) and the other
is of VarType 8 (String)
| Add
|
When a Single and a Long are added together, the data type of result is converted to a Double.
When the data type of result is a Variant of VarType 3 (Long), VarType 4 (Single), or VarType 7 (Date)
that overflows its legal range, result is converted to a Variant of VarType 5 (Double).
When the data type of result is a Variant of VarType 2 (Integer) that overflows its legal range, result is converted to a Variant of VarType 3 (Long).
If one or both operands are Null expressions, result is a Null. If both operands are Empty, result is Empty. However, if only one operand is Empty, the other operand is returned unchanged as result.
Example
This example determines total tax by using the + operator to add state and federal tax. After the calculation, TotalTax equals 1800.
| GrossPay = 10000
| // Assign gross pay.
|
| StateTax = .06 * GrossPay
| // Calculate state tax.
|
| FederalTax = .12 * GrossPay
| // Calculate federal tax.
|
| TotalTax = StateTax + FederalTax
| // Calculate total tax.
|