Navigation:  MCL Reference > Miscellaneous Functions >

Compare( )

Print this Topic Previous pageReturn to chapter overviewNext page

The function compares 2 values and return 1, 0, or -1 corresponding to "greater than", "equal to", and "smaller than" respectively. If any of the arguments is .Null., .Null. will be returned.

In Visual FoxPro string comparison using the native operators "<", ">" and "=" will be carried out up to the last character of the right hand side. This behaviour can be a trap for most people. You may keep away from this trap by using Compare( ).

 

Using operations >, < and =:

Comparison

Returned Value

Remark

"ABC"="AB"

.T.

In Visual FoxPro string comparison will be carried out up to the last character of the right hand side. Therefore "C" at the left hand side will be ignored

"ABC"<"AB"

.F.

"ABC">"AB"

.F.

"AB"="ABC"

.F.

In Visual FoxPro string comparison will be carried out up to the last character of the right hand side. Therefore "C" at the right hand side will be taken into account

"AB"<"ABC"

.T.

"AB">"ABC"

.F.

"AB"="AB"

.T.

 

3 > 4

.F.

3 = 3

.T.

4 < 3

.F.

.Null. > 3

.Null.

 

Using the Compare( ) function:

Comparison

Returned Value

Compare("ABC","AB")

1

Compare("AB","ABC")

-1

Compare("AB","AB")

0

Compare(3, 4)

-1

Compare(3, 3)

0

Compare(4, 3)

1

Compare(.Null., 3)

.Null.

 

Syntax

Compare(eValue1,eValue2)

 

Returns

Numeric

 

 

 


Page url: http://www.racematenet.com/english/help/index.html?compare.htm