Dictionary 객체의 문자열 키를 비교하기 위한 비교 모드를 설정 및 반환합니다.
구문
object.CompareMode[ = compare]
인수:
Object: 필수. 항상 Dictionary 객체의 이름입니다.
Compare: 선택사항. 제공된 경우 비교는 비교 모드를 나타내는 값입니다. 허용되는 값은 0(이진), 1(텍스트), 2(데이터베이스)입니다. 2보다 큰 값은 특정 LCID(로케일 ID)를 사용한 비교를 참조하기 위한 용도로 사용할 수 있습니다.
주석
이미 데이터가 포함된 Dictionary 객체의 비교 모드를 변경하려고 시도하면 오류가 발생합니다.
다음 예에서는 CompareMode 등록정보를 사용하는 방법을 보여 줍니다.
예 1:
Sub TextCompareExample
Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
' Set comparison mode to Text (case-insensitive)
d.CompareMode = vbTextCompare
' Add some keys and items.
d.Add "a", "Athens"
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
' Try to add a key that differs only in case
On Error Resume Next
d.Add "B", "Baltimore"
Number = Err.Number
If Number <> 0 Then
Msg = "Error: Key 'b' already exists."
Err.Clear
End If
On Error GoTo 0
End Sub
' Output: Error: Key 'b' already exists.
예 2:
Sub BinaryCompareExample
Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
' Set comparison mode to Binary (case-sensitive)
d.CompareMode = vbBinaryCompare
' Add some keys and items.
d.Add "x", "Xenon"
d.Add "y", "Yttrium"
d.Add "z", "Zirconium"
' Try to add a key "X" which is different from "x"
d.Add "X", "X-Ray"
End Sub
' Output: Dictionary Object Contain Keys: x,y,z,X Items: Xenon,Yttrium,Zirconium,X-Ray