This gives the answer 5.3333.
MsgBox 10 + 6 / 3
This gives the answer 12.
In the first example, the parentheses force10 + 6to be evaluated first before division by 3.
In the second example, the division of6/3takes precedence followed by the addition of 10.
Arithmetic Operators
The following operators—plus (+), minus (–), multiply (*), and divide (/)—do arithmetical
work.
* Operator
The*operator is used to multiply two numbers.
MsgBox 6 * 3
This gives the answer 18.
The numbers can be any numeric expressions. The data type of the result is that of the
most precise operand, ranging from Integer (least precise), Long, Single, Double, to Currency
(most precise). See Chapter 2 for more details on these data types. If one operand is Null,
then the result will be Null.
+ Operator
The+operator is used to add two numbers or expressions together.
MsgBox 4 + 2
The answer will be 6.
This operator can both add numbers and concatenate strings. String concatenation can
cause confusion, so it is best to use the&operator because you cannot always determine if
string concatenation will occur with+. See the example at the end of this section showing
how string concatenation can be affected by use of the+operator.
The numbers can be any numeric expressions. The data type of the result is that of the
most precise operand, ranging from Integer (least precise), Long, Single, Double, Currency
(most precise). If one operand is Null, then the result will be Null.
Here are some general rules of addition and concatenation:
Add if both operands are numeric.
Concatenate if both operands are strings.
Add if one operand is numeric and the other is a variant (not Null).
Concatenate if one operand is a string and the other is a variant (not Null).
72 Microsoft Access 2010 VBA Macro Programming