StrComp Function
Returns a Variant (Integer) indicating the result of a string comparison.
Syntax
StrComp(string1, string2[, compare])
The StrComp function syntax has these named arguments:
Part | Description |
---|---|
string1 | Required. Any valid string expression. |
string2 | Required. Any valid string expression. |
compare | Optional. Specifies the type of string comparison. If the compare argument is Null, an error occurs. If compare is omitted, the Option Compare setting determines the type of comparison. |
Settings
The compare argument settings are:
Constant | Value | Description |
---|---|---|
vbUseCompareOption | -1 | Performs a comparison using the setting of the Option Compare statement. |
vbBinaryCompare | 0 | Performs a binary comparison. |
vbTextCompare | 1 | Performs a textual comparison. |
vbDatabaseCompare | 2 | Microsoft Access only. Performs a comparison based on information in your database. |
Return Values
The StrComp function has the following return values:
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 |