STRCOMP

STRCOMP(string1, string2 [,compare])

Returns the result of a string comparison (Integer).


string1The first text string (String).
string2The second text string (String).
compare(Optional) A vbCompareMethod constant specifying the type of string comparison to use (Integer):
-1 = vbUseCompareOption (uses the "Option Compare" setting)
0 = vbBinaryCompare (case sensitive) (default)
1 = vbTextCompare (not case sensitive)
2 = vbDatabaseCompare (uses an Access database)

REMARKS
* This function is case sensitive (by default).
* The value returned is -1 when "string1" is less than "string2".
* The value returned is 0 when "string1" is equal to "string2".
* The value returned is 1 when "string1" is greater than "string2".
* The value returned is Null if either "string1" or "string2" is Null.
* If "compare" is left blank, then -1 is used. If there is no Option Compare statement provided then vbBinaryCompare (0) is used.
* If "compare" is Null, then an error occurs.
* You can use the STR function to return the text string of a number.
* You can use the STRCOMP$ function to return a String data type instead of Variant data type.
* You can use the STRCONV function to return the text string converted to a specific case or type.
* If you type in STRCOMP$ with valid arguments the editor will automatically change this function to just STRCOMP.
* The equivalent .NET function is [[Microsoft.VisualBasic.Strings.StrComp]]
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print StrComp("Monday", "Monday")                   '= 0  
Debug.Print StrComp("MONDAY", "monday") '= -1
Debug.Print StrComp("MONDAY", "monday", vbTextCompare) '= 0
Debug.Print StrComp("text", "text", vbBinaryCompare) '= 0
Debug.Print StrComp("text ", "text", vbBinaryCompare) '= 1
Debug.Print StrComp("Text", "text", vbBinaryCompare) '= -1
Debug.Print StrComp("Text", Null, vbBinaryCompare) '= Null
Debug.Print StrComp("text", "text", vbTextCompare) '= 0
Debug.Print StrComp("text ", "text", vbTextCompare) '= 1
Debug.Print StrComp("Text", "text", vbTextCompare) '= 0
Debug.Print StrComp(Null, "Text", vbBinaryCompare) '= Null
Debug.Print StrComp("3-D Settings Toolbar", "3D References", vbTextCompare) '= 1
Debug.Print StrComp("3-D Settings Toolbar", "3D Trendlines", vbTextCompare) '= -1

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top