Comparison Constants

The following table illustrates the contants and its description:

Table 11-5 Comparison Constants and Descriptions

Constant Value Description
vbBinaryCompare 0 Perform a binary comparison
vbTextCompare 1 Perform a textual comparison

The following example illustrates the use of the Comparison Constants:

Example 1:

Dim result
result = StrComp("Hello", "hello", vbBinaryCompare)
 
If result = 0 Then
    'Logic Strings are equal (Binary Comparison)
Else
    'Logic Strings are NOT equal (Binary Comparison)
End If
'Output -> Strings are Not equal (Binary Comparison) Logic

Example 2:

Dim result
result = StrComp("Hello", "hello", vbTextCompare)
 
If result = 0 Then
    'Logic Strings are equal (Text Comparison)
Else
    'Logic Strings are NOT equal (Text Comparison)
End If
 
'Output -> Strings are equal (Text Comparison) Logic

Example 3:

Dim str1, str2
 
str1 = "Apple"
str2 = "apple"
 
If StrComp(str1, str2, vbTextCompare) < 0 Then
    'Logic If
Else
    'Logic Else 
End If
 
'Output -> apple comes before Apple (Binary) ( Logic Else )