Relational Operators

Relational operators work with all data types and return a Logical value. The following table lists the relational operators.

Relational Operators

Operator

Action

Code

<

Less than

? 23 < 54

>

Greater than

? 1 > 2

=

Equal to

? cVar1 = cVar

<>, #, !=

Not equal to

? .T. <> .F.

<=

Less than or equal to

? {^1998/02/16} <= {^1998/02/16}

>=

Greater than or equal to

? 32 >= nHisAge

==

Character string comparison

? status == "Open"

The == operator can be used when an exact comparison of character strings is needed. If two character expressions are compared with the == operator, the expressions on both sides of the == operator must contain exactly the same characters, including blanks, to be considered equal. The SET EXACT setting is ignored when character strings are compared using ==. See SET EXACT for more information on using the == operator to compare character strings.

You also can use the equal to (=) operator to determine if two object references refer to the same object. The following example demonstrates a simple usage:

CLEAR ALL
X = CREATEOBJECT('Form')
Y = CREATEOBJECT('Form')
? X = Y  && Displays false (.F.)
Z = X
? X = Z  && Displays true (.T.)

See Also

Reference

Logical Operators

CREATEOBJECT( ) Function

SET EXACT Command

Operators (Visual FoxPro)