Comparison Operators
Used to compare expressions.
Syntax
result = expression1 comparison_operator expression2
Arguments:
-
Result: Any Boolean value.
-
Expression: Any expression.
-
Comparison_Operator: Any comparison operator.
Remarks
The Is 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:
Table 11-26 The list of the comparison operators
Operator | Description | True if | False if | Null if |
---|---|---|---|---|
< | Less than | exp1 < exp2 | exp1 >= exp2 | exp1 or exp2 = Null |
<= | Less than or equal to | exp1 <= exp2 | exp1 > exp2 | exp1 or exp2 = Null |
> | Greater than | exp1 > exp2 | exp1 <= exp2 | exp1 or exp2 = Null |
>= | Greater than or equal to | exp1 >= exp2 | exp1 < exp2 | exp1 or exp2 = Null |
= | Equal to | exp1 = exp2 | exp1 <> exp2 | exp1 or exp2 = Null |
<> | Not equal to | exp1 <> exp2 | exp1 = exp2 | exp1 or exp2 = 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 expressions are compared or what results from the comparison, depending on the underlying subtype:
Table 11-27 Results of Comparison with Expressions
If | Then |
---|---|
Both expressions are numeric | Perform a numeric comparison. |
Both expressions are strings | Perform a string comparison. |
One expression is Empty and the other is numeric | 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. |
Both expressions are Empty | The expressions are equal. |
The following examples illustrates the use of comparison operator.
Example 1:
Dim num1, num2, result
num1 = 10
num2 = 20
result = num1 < num2
'result -> true
Example 2:
Dim num3, num4, result1
num3 = 10
num4 = 10
result1 = num3 <= num4
'result1 -> true
Example 3:
Dim num5, num6, result2
num5 = 30
num6 = 20
result2 = num5 > num6
'result2 -> true
Example 4:
Dim num7, num8, result3
num7 = 30
num8 = 30
result3 = num7 >= num8
'result3 -> true
Example 5:
Dim str1, str2, result4
str1 = "Hello"
str2 = "Hello"
result4 = str1 = str2
'result4 -> true
Example 6:
Dim str3, str4, result5
str3 = "Hello"
str4 = "World"
result5 = str3 <> str4
'result5 -> true
Example 7:
Dim str5, str6, result6
str5 = "Apple"
str6 = "Banana"
result6 = str5 < str6
'result6 -> true
Example 8:
Dim emptyExpr1, str8, result9
emptyExpr1 = ""
str8 = "Banana"
result9 = emptyExpr1 < str8
'result9 -> true
Example 9:
Dim emptyExpr2, emptyExpr3, result10
emptyExpr2 = ""
emptyExpr3 = ""
result10 = emptyExpr2 = emptyExpr3
'result10 -> true