비교 상수

다음 테이블은 상수와 해당 설명을 보여줍니다.

표 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 )