Relational (comparison) operators

Relational operators (also called comparison operators) compare two expressions.

Syntax

expr1 operator expr2

Elements

expr1, expr2

Any expressions.

operator

One of the following operators: <, >, <=, =<, >=, =>, <>, ><, =.

Return value

An expression consisting of two numeric operands and a relational (comparison) operator evaluates to True (-1), False (0), or, if either or both of the operands is NULL, to NULL.

For a description of the way in which LotusScript® treats the values True (-1) and False (0), see "Boolean values" in the chapter "Data Types, Constants, and Variables".

Comparing two expressions, neither of which is NULL, returns the following values:

Operator

Operation

TRUE if

FALSE if

<

Less than

expr1 < expr2

expr1 >= expr2

<= or =<

Less than or equal to

expr1 <= expr2

expr1 > expr2

>

Greater than

expr1 > expr2

expr1 <= expr2

>= or =>

Greater than or equal to

expr1 >= expr2

expr1 < expr2

=

Equal to

expr1 = expr2

expr1 <> expr2

<> or ><

Not equal to

expr1 <> expr2

expr1 = expr2

Usage

LotusScript interprets the relational operator as either numeric comparison or string comparison, depending on the data types of expr1 and expr2. The following table lists these interpretations. The numeric data types are Integer, Long, Single, Double, Currency, and (in a Variant variable only) Date/Time.

One expression

Other expression

Operation

Numeric

Numeric

Numeric comparison.

Numeric

Variant of numeric data type or Variant containing string value that can be converted to a number

Numeric comparison.

Numeric

Variant containing String value that cannot be converted to a number

Type mismatch error occurs.

Numeric

Variant that contains EMPTY

Numeric comparison, with 0 substituted for the EMPTY expression.

String

String

String comparison.

String

Variant (other than NULL)

String comparison.

String

Variant that contains EMPTY

String comparison.

Variant containing string value

Variant containing string value

String comparison.

Variant that contains EMPTY

Variant containing string value

String comparison, with the empty string ("") substituted for the EMPTY expression.

Variant of numeric data type

Variant of numeric data type

Numeric comparison.

Variant that contains EMPTY

Variant of numeric data type

Numeric comparison, with 0 substituted for the EMPTY expression.

Variant of numeric data type

Variant containing string value

Numeric comparison. The numeric expression is less than the string expression.

Variant that contains EMPTY

Variant that contains EMPTY

Expressions are equal.

String comparison

For string comparison, the Option Compare statement sets the comparison method:

If you omit the Option Compare statement, the default method of string comparison is the same as Option Compare Case, Pitch.

To compare strings, LotusScript examines the two strings character by character, starting with the first character in each string. The collating sequence values (positions in the character sort sequence) of the two characters are compared.

If the end of both strings is reached simultaneously by this process, then neither string has been found larger than the other, and the strings are equal. Otherwise the longer string is the larger string.

Data type conversion

When the operands in a comparison are of different data types, LotusScript automatically converts data types where possible to make the operands compatible before comparing them:

Relational operations on date/time values are performed on both the date and the time. For two date/time values to be equal, both their date and time portions must be equal. For inequality, either may be unequal. For all other operations, the comparison is first done on the date portions. If the date portions are equal, the comparison is then done on the time.

Examples

This example compares numbers.

Print 1 < 2                              ' Prints True
Print 2 > 1                              ' Prints True
Print 1 <> 2                             ' Prints True
Print 2 >= 2                             ' Prints True
Print 2 <= 2                             ' Prints True
Print 2 = 2                              ' Prints True

This example compares strings.

Print "hello" < "hellp"                  ' Prints True
Dim myVar As Variant, myStr As Variant
myStr = "34"
myVar = 34
Print myVar < myStr                      ' Prints True
Print 45 > myStr                         ' Prints True
Print "45" > myVar                       ' Prints True

This example compares two numbers in a more detailed manner:

anInt% = 10
anotherInt% = 15
Dim theResultV As Variant

If anInt% > anotherInt% Then
   Print anInt% & " is greater than " & anotherInt% & "."
Else
   Print anInt% & " is less than or equal to " & _
        anotherInt% & "."
End If
' Output: 10 is less than or equal to 15.
theResultV = (anInt% > anotherInt%)
Print theResultV
' Output: False
Print CInt(anInt% > anotherInt%)
' Output: 0
Print (anInt% > anotherInt%) = False 
' Output: True
' because the expression (anInt% > anotherInt%) = False
' is True.

Additional Documentation | Trademarks |