Simple example to show the usage of Dictionary in VBS
Set hash = CreateObject ("Scripting.Dictionary")
hash.add "A", "Apple" 'Inserting values into dictionary
hash.add "B", "Ball" 'Inserting valuesinto Dictionary
hash.item("b") = "Note Dictionary is Case Sensitive" 'The dictionary's "item" method can be used to do the same job as "add "
'hash.CompareMode = 1
'This must be places immediately after the CreateObject statement and before any items are added.
'If that's done then the keys will no longer be case sensitive.
msgbox "A for "& hash.item("A")
keys = hash.Keys 'Keys - returns an array containing the key words
items = hash.Items 'Items - returns an array containing the values
for i = 0 to hash.Count - 1
msgbox Keys(i) & " for " & Items(i)
next
hash.Remove("A") 'To remove individual values from dictionary
hash.RemoveAll 'To remove all values into Dictionary
Set hash = CreateObject ("Scripting.Dictionary")
hash.add "A", "Apple" 'Inserting values into dictionary
hash.add "B", "Ball" 'Inserting valuesinto Dictionary
hash.item("b") = "Note Dictionary is Case Sensitive" 'The dictionary's "item" method can be used to do the same job as "add "
'hash.CompareMode = 1
'This must be places immediately after the CreateObject statement and before any items are added.
'If that's done then the keys will no longer be case sensitive.
msgbox "A for "& hash.item("A")
keys = hash.Keys 'Keys - returns an array containing the key words
items = hash.Items 'Items - returns an array containing the values
for i = 0 to hash.Count - 1
msgbox Keys(i) & " for " & Items(i)
next
hash.Remove("A") 'To remove individual values from dictionary
hash.RemoveAll 'To remove all values into Dictionary
No comments:
Post a Comment