StrComp function
Returns a value that indicates the result of a string comparison.
StrComp(string1, string2[, compare])
Parameters
String1
Required option. Any valid string expression.
string2
Required option. Any valid string expression.
Compare
Options available. Indicates the numeric value of the comparison type to use when calculating the string. If omitted, a binary comparison is performed. For numeric values, see the "Settings" section.
Set up
The compare parameter can have the following values:
| Constants |
value |
Description |
| Vbbinarycompare |
0 |
Performs a binary comparison. |
| vbTextCompare |
1 |
Performs a text comparison. |
return value
The StrComp function has the following return value:
| if |
StrComp return |
| String1 less than string2 |
-1 |
| String1 equals string2 |
0 |
| String1 is larger than string2 |
1 |
| string1 or string2 is Null |
Null |
Description
The following example uses the StrComp function to return the result of a string comparison. If the third argument is 1 to perform a text comparison, if the third argument is 0 or omit to perform a binary comparison.
Dim MyStr1, MyStr2, MyCompMyStr1 = "ABCD": MyStr2 = "ABCD" define variable. MyComp = StrComp ( mystr1 , mystr2 , 1 ) ' return 0 . MyComp = StrComp ( mystr1 , mystr2 , 0 ) ' return -1 . MyComp = StrComp ( mystr2 , mystr1 ) ' returns 1 .