published Thursday, July 7th, 2011 at 5:15 pm by
Administrator
'========================================================
' NAME: FSO_Dictionary_Obj1.vbs
' AUTHOR: Neal Walters , Amerisoft Inc
' DATE : 3/26/2005
' http://VBScript-Training.com
'========================================================
Option Explicit
Dim dict, empnum
Set dict = CreateObject("Scripting.Dictionary")
dict.Add 101, "John Doe"
dict.Add 102, "Fred Flinstone"
dict.Add 103, "Wilma Flinstone"
dict.Add 104, "Barnie Rubble"
dict.Add 222, "Betty Rubble"
empnum = -1
Do While empnum <> 0
empnum = InputBox("Type in an employee number:")
If empnum = "" Then
empnum = 0
Exit Do
End If
empnum = CInt(empnum)
WScript.Echo "For empnum=" & empnum & " the employee name = " & dict.Item(empnum)
Loop
'=========================================================
' NAME: FSO_Dictionary_Obj2.vbs
' AUTHOR: Neal Walters , Amerisoft Inc
' DATE : 3/26/2005
' http://VBScript-Training.com
'=========================================================
Option Explicit
Dim dict, empnum, newname, oldname
Set dict = CreateObject("Scripting.Dictionary")
dict.Add 101, "John Doe"
dict.Add 102, "Fred Flinstone"
dict.Add 103, "Wilma Flinstone"
dict.Add 104, "Barnie Rubble"
dict.Add 222, "Betty Rubble"
Dim newkey, newitem
empnum = -1
Do While empnum <> 0
empnum = InputBox("Type in an employee number of the employee you want to change or type in ADD or DEL:",,,1000,6000)
If empnum = "" Then
empnum = 0
WScript.Echo "empnum = 0 so loop is stopping"
Exit Do
End If
If empnum = "ADD" Then
newkey = InputBox ("What is the key for the new employee:",,,1000,6000)
newitem = InputBox ("What is the name for the new employee:,,,1000,6000")
dict.Add newkey, newitem
empnum = -1
ElseIf empnum = "DEL" Then
newkey = InputBox ("What is the key for the employee to be deleted:",,,1000,6000)
dict.Remove cint(newkey)
empnum = -1
Else
empnum = CInt(empnum)
newname = InputBox("Type in new name for employee " & dict.Item(empnum),,,1000,6000 )
oldname = dict.Item(empnum)
dict.Item(empnum)= newname
WScript.Echo "For empnum=" & empnum & " old employee name = " & oldname & _
" and new name = " & newname
End If
Loop
WScript.Echo "Values of all employee names:"
Dim empArray, i, empkeys
empArray = dict.Items ' Get the items/values
empKeys = dict.Keys ' Get the keys
For i = 0 To UBound(empArray) ' Iterate the array.
WScript.Echo i & " empnum=" & empKeys(i) & _
" empname=" & empArray (i)
Next
'========================================================
' NAME: FSO_Dictionary_Obj3.vbs
' AUTHOR: Neal Walters , Amerisoft Inc
' DATE : 3/26/2005
' http://VBScript-Training.com
'========================================================
Option Explicit
Dim dict, empnum, newname, oldname, house1, house2,emp1
Set house1 = CreateObject("Scripting.Dictionary")
Set house2 = CreateObject("Scripting.Dictionary")
Set emp1 = CreateObject("Scripting.Dictionary")
house1.Add "exterior","brick"
house1.Add "trimcolor","white"
house1.Add "sqft",2500
house1.Add "owner","John Doe"
house1.Add "address","123 Main Street"
house1.Add "city","Dallas"
house1.Add "state","TX"
house1.Add "zip","75080"
house2.Add "squarefeet",2500
house2.Add "trimcolor","yellow"
house2.Add "owner","Movie Star"
house2.Add "address","444 Star Island"
house2.Add "city","Miami"
house2.Add "state","FL"
emp1.Add "Name","John Doe"
emp1.Add "City","Naples"
emp1.Add "State","Florida"
printAnyDictionaryObject house1,"House1"
printAnyDictionaryObject house2,"Before Paint: House2"
Painthouse house2,"green"
printAnyDictionaryObject house2,"After Paint: House2"
printAnyDictionaryObject emp1,"Emp1"
WScript.Echo "THE END "
'-------------------------------------------------------
' Nice subroutine to print any dictionary object
'-------------------------------------------------------
sub printAnyDictionaryObject(mydictobj,mydescription)
WScript.Echo "List all values in dictionary object=" & mydescription & VbCrLf
Dim myArray, i, myKeys
myArray = mydictobj.Items ' Get the items/values
myKeys = mydictobj.Keys ' Get the keys
For i = 0 To UBound(myArray) ' Iterate the array.
WScript.Echo i & " key=" & myKeys(i) & _
" value=" & myArray (i)
Next
WScript.Echo " "
End Sub
Sub Painthouse(mydictobj, newcolor)
mydictobj.item("trimcolor") = newcolor
End Sub