Comparison operators

Comparison operators

Used to compare expressions.

Syntax

result = expression1 comparisonoperator expression2

result = string Like pattern

Comparison operators have these parts:

Part Description
expression Any expression.
comparisonoperator Any comparison operator.
string Any string expression.
pattern Any string expression or range of characters.

Remarks

The Like operator has specific comparison functionality that differs from the operators in the following table. The following table contains a list of the comparison operators and the conditions that determine whether result is True, False, or Null:

Operator Description True if False if Null if
< Less than expression1 < expression2 expression1 >= expression2 expression1 or expression2 = Null
<= Less than or equal to expression1 <= expression2 expression1 > expression2 expression1 or expression2 = Null
> Greater than expression1 > expression2 expression1 <= expression2 expression1 or expression2 = Null
>= Greater than or equal to expression1 >= expression2 expression1 < expression2 expression1 or expression2 = Null
= Equal to expression1 = expression2 expression1 <> expression2 expression1 or expression2 = Null
<> Not equal to expression1 <> expression2 expression1 = expression2 expression1 or expression2 = Null

When comparing two expressions, you may not be able to easily determine whether the expressions are being compared as numbers or as strings. The following table shows how the expressions are compared or what results when either expression is not a Variant:

If Then
Both expressions are numeric data types (Byte, Boolean, Integer, Long, Single, Double, Date, 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 that is, or can be, a number Perform a numeric comparison.
One expression is a numeric data type and the other is a string Variant that can't be converted to a number Perform a string comparison.
One expression is a String and the other is any Variant (except a Null) Perform a string comparison.
One expression is Empty and the other is a numeric data type Perform a numeric comparison, using 0 as the Empty expression.
One expression is Empty and the other is a String Perform a string comparison, using a zero-length string ("") as the Empty expression.

If expression1 and expression2 are both Variant expressions, their underlying type determines how they are compared. The following table shows how the expressions are compared or what results from the comparison, depending on the underlying type of the Variant:

If Then
Both Variant expressions are numeric Perform a numeric comparison.
Both Variant expressions are strings Perform a string comparison.
One Variant expression is numeric and the other is a string The numeric expression is less than the string expression.
One Variant expression is Empty and the other is numeric Perform a numeric comparison, using 0 as the Empty expression.
One Variant expression is Empty and the other is a string Perform a string comparison, using a zero-length string as the Empty expression.
Both Variant expressions are Empty The expressions are equal.

Note   If a Currency is compared with a Single or Double, the Single or Double is converted to a Currency. This causes any fractional part of the Single or Double value less than 0.0001 to be lost and may cause two values to compare as equal when they are not. When a Single is compared to a Double, the Double is rounded to the precision of the Single.