See Also Syntax 1 Example Syntax 2 Example
Used to find the difference between two numbers or to indicate the negative value of an operand.
Syntax 1
result = operand1 - operand2
Syntax 2
-number
Remarks
In Syntax 1, the - operator is the arithmetic subtraction operator used to find the difference between two numbers. The operands can be any numeric expression .
The data type The order of precision, from least to most precise, is Integer, Long, Single, Currency, Double. The following are exceptions to this order:
When subtraction involves a Single and a Long, 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 If an operand is Empty (VarType 0), it is treated as if it were 0.
In Syntax 2, the - operator is used as the unary negation operator to indicate the negative value of an operand. As with Syntax 1, the operand can be any numeric constant, variable, expression, or any function that returns a number.
Arithmetic Operators
Comparison Operators
Concatenation Operators
Logical Operators
Operator Precedence
Other Operators
VarType Function
The example subtracts a user-supplied number from 1000 and displays the result To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim N As Double, Result As Double ' Declare variables.
N = InputBox ("Enter a number.") ' Get a number.
Result = 1000 -N
MsgBox "1000 minus " & N & " is " & Result ' Display result.
End Sub
The example uses the - operator to indicate a negative value of a number. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim N As Double, MinusN As Double ' Declare variables.
N = InputBox("Enter a number") ' Get a number.
MinusN = -N ' Use negation operator.
MsgBox "Negative " & N & " is " & MinusN ' Display result.
End Sub