


Comparison Operators
| Operator
| Meaning
| True if
| False if
| Null if
|
| <
| Less than
| expr1 < expr2
| expr1 >= expr2
| expr1 or expr2 = Null
|
| <=
| Less than or equal to
| expr1 <= expr2
| expr1 > expr2
| expr1 or expr2 = Null
|
| >
| Greater than
| expr1 > expr2
| expr1 <= expr2
| expr1 or expr2 = Null
|
| >=
| Greater than or equal to
| expr1 >= expr2
| expr1 < expr2
| expr1 or expr2 = Null
|
| =
| Equal to
| expr1 = expr2
| expr1 <> expr2
| expr1 or expr2 = Null
|
| <>
| Not equal to
| expr1 <> expr2
| expr1 = expr2
| expr1 or expr2 = Null
|
| If
| Then
|
| Both expressions are numeric data types (Integer, Long, Single, Double, or
Currency)
| Perform a numeric comparison.
|
| Both expressions are String
| Perform a string comparison.
|
| One expression is a numeric data type and the other is a Variant of VarType
2-7 (a numeric data type) or VarType 8 (String) that can be converted to a number
| Perform a numeric comparison.
|
| One expression is a numeric data type and the other is a Variant of VarType 8
(String) that can't be converted to a number
| The numeric expression is less than the String expression.
|
| One expression is a String and the other is a Variant of VarType 8 (String)
| Perform a string comparison.
|
| One expression is Empty and the other is a numeric data type
| Perform a numeric comparison.
|
| One expression is Empty and the other is a String
| Perform a string comparison.
|
| One expression is a numeric data type and the other is a Variant of VarType 8
(String)
| A Type mismatch error occurs.
|
| If
| Then
|
| Both Variant expressions are of VarType 2-7 (numeric data types)
| Perform a numeric comparison.
|
| Both Variant expressions are of VarType 8 (String)
| Perform a string comparison.
|
| One Variant expression is of VarType 2-7 (a numeric data type) and the other
is of VarType 8 (String)
| The numeric expression is less than the String expression.
|
| One Variant expression is Empty and the other is of VarType 2-7 (a numeric
data type)
| Perform a numeric comparison.
|
| One Variant expression is Empty and the other is of VarType 8 (String)
| Perform a string comparison.
|
| Both Variant expressions are Empty
| The expressions are equal.
|
Example
This example shows a typical use of a comparison operator to evaluate the relationship between variables A and B. An appropriate message prints depending on whether the expression A <= B is True (-1) or False (0). The other comparison operators can be used in a similar way.
If A <= B Then
Debug.Print "A is less than or equal to B."
Else
Debug.Print "A is greater than B."
End If