次の表は、定数とその説明を示しています:
表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 )