Sub DicDemo()
'Early Binding method requires Reference: MicroSoft Scripting Runtime, scrrun.dll
Dim a, i As Integer ' Create some variables.
Dim pos As Integer
'Dim d As Object 'Late Binding method
Dim s As String
Dim d As Dictionary 'Early Binding method
Set d = New Dictionary 'Early Binding Method
'Set d = CreateObject("Scripting.Dictionary") 'Late Binding method
d.Add "a", "Athens" ' Add some keys and items.
d.Add "aa", "Athens" '
Rem d.Add "a", "Belgrade" 'Illegal, no duplicate keys allowed.
d.Add "b", "Cairo"
d.Add "c", "Belgrade"
a = d.Items ' Get the items.
'a = d.Keys ' Get the keys.
For i = 0 To d.Count - 1 ' Iterate the array.
s = s & a(i) & "<BR>" ' Return results.
Next i
pos = WorksheetFunction.Match("Athens", WorksheetFunction.Transpose(a), 0)
MsgBox "Athens = position " & pos
pos = WorksheetFunction.Match("cairo", WorksheetFunction.Transpose(a), 0)
MsgBox "Cairo = position " & pos
MsgBox "Item Position 1 = " & d.Items(1) & vbCrLf & _
"Item Position 3 = " & d.Items(3)
d.Items
On Error Resume Next
pos = 0
pos = WorksheetFunction.Match("Athens, Greece", WorksheetFunction.Transpose(a), 0)
If pos <> 0 Then
MsgBox "Athens, Greece = position " & pos
Else
MsgBox "Athens, Greece = Not Found"
End If
MsgBox d.Keys(1), , d.Items(1)
End Sub