Skip to content

Instantly share code, notes, and snippets.

@simply-coded
Last active May 31, 2018 00:11
Show Gist options
  • Save simply-coded/25bd687b1e780773b8e52bc01e7c5947 to your computer and use it in GitHub Desktop.
Save simply-coded/25bd687b1e780773b8e52bc01e7c5947 to your computer and use it in GitHub Desktop.
Dictionaries inside of dictionaries example using VBScript.
'**************************
'Name: Dictionary Inception
'Author: Jeremy England
'Company: SimplyCoded
'Version: rev.001
'Date: 02/20/2016
'**************************
Set contact = CreateObject("Scripting.Dictionary")
contact.Add "Ben", details("25","(820)-828 2828")
contact.Add "Jacob", details("56","(232)-234 9834")
'view single item
'MsgBox contact.Item("Jacob").Item("Phone")
'view all items
'MsgBox contactDetails("Jacob")
'change item
'contact.Item("Ben").Item("Age") = 26
'MsgBox contactDetails("Ben")
'change sub key
'contact.Item("Ben").Key("Phone") = "Number"
'MsgBox contactDetails("Ben")
'change key
'contact.Key("Ben") = "Michael"
'MsgBox contactDetails("Michael")
'view all main keys
'MsgBox Join(contact.Keys())
'view all main items of a key
'MsgBox Join(contact.Items()(0).Items)
'MsgBox Join(contact.Items()(1).Items)
'add details
Function details(age, phone)
Set details = CreateObject("Scripting.Dictionary")
details.Add "Age",age
details.Add "Phone",phone
End Function
'join all details together
Function contactDetails(person)
contactDetails = person & ":" & vbLf
allKeys = contact.Item(person).Keys
allItms = contact.Item(person).Items
For i = 0 To UBound(allKeys)
contactDetails = contactDetails & " " & allKeys(i) & ": " & allItms(i) & vbLf
Next
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment