forked from Vitosh/VBA_personal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDictionaryExample.vb
53 lines (40 loc) · 1.11 KB
/
DictionaryExample.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Sub MyDictionary()
'Add
Dim myDict As New Scripting.Dictionary
myDict.Add "Peter", "Peter is a friend."
myDict.Add "George", "George is a guy I know."
myDict.Add "Salary", 1000
'Exists
If myDict.Exists("Salary") Then
Debug.Print myDict("Salary")
myDict("Salary") = myDict("Salary") * 2
Debug.Print myDict("Salary")
End If
'Remove
If myDict.Exists("George") Then
myDict.Remove ("George")
End If
'Items
Dim item As Variant
For Each item In myDict.Items
Debug.Print item
Next item
'Keys
Dim key As Variant
For Each key In myDict.Keys
Debug.Print key
Next key
'Remove All
myDict.RemoveAll
'Compare Mode
myDict.CompareMode = BinaryCompare
myDict.Add "PeTeR", "Peter written as PeTeR"
myDict.Add "PETeR", "Peter written as PETeR"
PrintDictionary myDict
End Sub
Public Sub PrintDictionary(myDict As Object)
Dim key As Variant
For Each key In myDict.Keys
Debug.Print key; "-->"; myDict(key)
Next key
End Sub