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:

  • Option Compare Case and Option Compare NoCase specify comparison using the character collating sequence determined by the HCL software that you are using. Case specifies case-sensitive comparison, and NoCase specifies case-insensitive comparison.
  • Option Compare Pitch and Option Compare NoPitch specify comparison using the character collating sequence determined by the HCL software that you are using. Pitch specifies pitch-sensitive comparison, and NoPitch specifies pitch-insensitive comparison. These options apply to Asian (double byte) characters.
  • Option Compare Binary specifies string comparison in the platform's collating sequence. The effect is platform sort-order, case-sensitive comparison.

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 these values are notequal, the string whose character has the larger collating sequence value (appears later in the sort sequence) is the largerstring.
  • If the collating sequence values of the pair of characters are the same, andboth strings contain more characters, then the character comparison proceeds to the next character.

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:

  • LotusScript converts an EMPTY-valued operand to 0 if the other operand is numeric.
  • When LotusScript performs a comparison operation on operands of different numeric data types, the value of the operand with the lesser type is promoted to the greater type before the operation is carried out. The ordering of the numeric data types from least to greatest is:

    BOOLEAN

    BYTE

    INTEGER

    LONG

    SINGLE

    DOUBLE

    CURRENCY

  • Conversion of a value of type SINGLE or DOUBLE to a value of type CURRENCY may cause overflow or loss of precision.
  • When a SINGLE value is compared to a DOUBLE, the DOUBLE is rounded to the precision of the SINGLE.
  • Strings containing values that can be interpreted as numeric types will be converted to numeric types, where necessary.

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.