下表说明了常量及其说明:
表 11-5 比较常量和说明
| 常量 | 值 | 说明 |
|---|---|---|
vbBinaryCompare |
0 | 执行二进制比较 |
vbTextCompare |
1 | 执行文本比较 |
以下示例说明了比较常量的用法:
示例 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
示例 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
示例 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 )