StrComp
- Last UpdatedJul 18, 2023
- 1 minute read
Returns an integer that is the result of the comparison of two strings.
The required String1 argument is any valid string expression. The required String2 argument is any valid string expression.
The optional Compare argument is a numeric expression that specifies the type of string comparison. It can be omitted, 0, or 1. Specify 0 (default) to perform a binary comparison. Specify 1 to perform a textual comparison. If compare is Null, an error occurs.
Syntax
StrComp(String1, String2)
String1:
A string or expression that can represent a valid text value.
String2:
A string or expression that can represent a valid text value.
Return Value
Returns a variant containing an integer data type indicating the result of the string compare:
-
Returns -1 where String1 is less than String2.
-
Returns 0 where String1 is equal to String2.
-
Returns 1 where String1 is greater than String2.
-
Returns Null where String1 or String2s Null.
Example
Dim strTest1 as String
Dim strTest2 as String
Dim strTest3 as String
Dim vntComp
strTest1 = "ABCD"
strTest2 = "abcd"
strTest3 = NULL
vntComp = StrComp(strTest1, strTest2) ' Returns -1 (less than)
vntComp = StrComp(strTest1, strTest1) ' Returns 0 (equal to)
vntComp = StrComp(strTest2, strTest1) ' Returns 1 (greater than)
vntComp = StrComp(strTest1, strTest3) ' Returns NULL (strTest3 is NULL)