LOTUSSCRIPT LANGUAGE


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

Syntax

expr1 operator expr2

Elements

expr1, expr2


operator
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:
OperatorOperationTRUE ifFALSE if
<Less thanexpr1 < expr2expr1 >= expr2
<= or =<Less than or equal toexpr1 <= expr2expr1 > expr2
>Greater thanexpr1 > expr2expr1 <= expr2
>= or =>Greater than or equal toexpr1 >= expr2expr1 < expr2
=Equal toexpr1 = expr2expr1 <> expr2
<> or ><Not equal toexpr1 <> expr2expr1 = 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 expressionOther expressionOperation
NumericNumericNumeric comparison.
NumericVariant of numeric data type or Variant containing string value that can be converted to a numberNumeric comparison.
NumericVariant containing String value that cannot be converted to a numberType mismatch error occurs.
NumericVariant 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 valueVariant containing string valueString comparison.
Variant that contains EMPTY Variant containing string valueString comparison, with the empty string ("") substituted for the EMPTY expression.
Variant of numeric data typeVariant of numeric data typeNumeric comparison.
Variant that contains EMPTYVariant of numeric data typeNumeric comparison, with 0 substituted for the EMPTY expression.
Variant of numeric data typeVariant containing string valueNumeric 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.

See Also