contents.gifindex.gifprev1.gifnext1.gif

+ Operator

Purpose

Used to sum two numbers.

Syntax

result = operand1 + operand2

Notes

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 is to occur. If at least one operand is not a Variant, the following rules apply.

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 either operand is a Null (VarType 1), result is a Null.

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


For simple arithmetic addition involving only operands of numeric data types, the data type of result is usually the same as that of the most precise operand. The order of precision, from least to most precise, is Integer, Long, Single, Double, Currency. The following are exceptions to this order:

traxhelp00090000.gif When a Single and a Long are added together, the data type of result is converted to a Double.

traxhelp00090000.gif 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).

traxhelp00090000.gif 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.