StrComp Function

Description

Returns a value indicating the result of a string comparison.

Syntax

StrComp(string1, string2[, compare])

The StrComp function syntax has these named arguments:

Part

Description

string1

Any valid string expression.

string2

Any valid string expression.


Part

Description

compare

Specifies the type of string comparison. The compare argument can be omitted, it can be 0 or 1, or it can be the value of the CollatingOrder property of a Field object. Specify 0 (default) to perform a binary comparison. Specify 1 to perform a textual comparison. Specify the return value of the CollatingOrder property if you want to sort or compare values from a database in the same way the database itself would. If compare is Null, an error occurs. If compare is omitted, the Option Compare setting determines the type of comparison.


Remarks

If

StrComp returns

string1 is less than string2

-1

string1 is equal to string2

0

string1 is greater than string2

1

string1 or string2 is Null

Null


See Also

Option Compare Statement.

Example

This example uses the StrComp function to return the results of a string comparison. If the third argument is 1, a textual comparison is performed; if the third argument is 0 or omitted, a binary comparison is performed.


MyStr1 = "ABCD": MyStr2 = "abcd"                    ' Define variables.= StrComp(MyStr1, MyStr2, 1)                ' Returns 0.= StrComp(MyStr1, MyStr2, 0)                ' Returns -1.= StrComp(MyStr2, MyStr1)                    ' Returns 1.