StrComp Function

Description

Returns a value indicating the result of a string comparison.

Syntax

StrComp(string1,string2[,compare])

The StrComp function syntax has these parts:

Part

Description

string1

Any valid string expression.

string2

Any valid string expression.

compare

Number specifying the type of string comparison. Specify a 1 to perform a textual comparison. Specify a 0 (default) to perform a binary comparison. If compare is Null, an error occurs. If compare is omitted, the setting of Option Compare is used to determine the type of comparison.


Return Values

Value

Description

-1

string1 is less than string2.

0

string1 is equal to string2.

1

string1 is greater than string2.

Null

string1 or string2 is Null.


Remarks

Note

When Option Compare Text is specified, comparisons are textual and case-insensitive. When Option Compare Binary is specified, comparisons are strictly binary.

See Also

Option Compare Statement.

Example

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


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