Syntax 1 |
expression1 – expression2 |
||
Syntax 2 |
–expression |
||
Description |
Returns the difference between expression1 and expression2 or, in the second syntax, returns the negation of expression. |
||
Comments |
Syntax 1 The type of the result is the same as that of the most precise expression, with the following exceptions: |
||
|
If one |
and the other |
then the type |
|
Long |
Single |
Double |
|
Boolean |
Boolean |
Integer |
|
A runtime error is generated if the result overflows its legal range. When either or both expressions are Variant, then the following additional rules apply:
|
||
|
Syntax 2 If expression is numeric, then the type of the result is the same type as expression, with the following exception:
|
||
|
In 2's compliment arithmetic, unary minus may result in an overflow with Integer and Long variables when the value of expression is the largest negative number representable for that data type. For example, the following generates an overflow error: Sub Main() When negating variants, overflow will never occur because the result will be automatically promoted: integers to longs and longs to doubles. |
||
Example |
This example assigns values to two numeric variables and their difference to a third variable, then displays the result. Sub Main() |
||
See Also |
Operator Precedence (topic). |
Symbols |