Method: StrComp for VBS
- Updated2024-09-12
- 1 minute(s) read
Methods > Method: StrComp for VBS
Method: StrComp for VBS
Compares two texts.
vStrComp = Object.StrComp(string1, string2, [compare])
| Object | VBS Object with this method. You do not need to specify this object. | ||||||||||
| string1 | Variant Specifies a text. | ||||||||||
| string2 | Variant Specifies a text. | ||||||||||
| [compare] | Variant Specifies the type of comparison. Possible settings are vbBinaryCompare and vbTextCompare. If you do not specify compare, the Strcomp method performs a binary comparison. | ||||||||||
| vStrComp | Variant Receives the result of the text comparison. Possible return values:
|
The following example compares two texts:
Dim MyStr1, MyStr2, MyComp MyStr1 = "ABCD" MyStr2 = "abcd" MyComp = StrComp(MyStr1, MyStr2, vbTextCompare) ' Returns 0 Call MsgBox(MyComp) MyComp = StrComp(MyStr1, MyStr2, vbBinaryCompare) ' Returns -1 Call MsgBox(MyComp)