Friday, February 4, 2011

Creating dictionary using Vbscript


Dim vKey
Dim sItem, sMsg
Dim oDict

'--- Creating a dictionary object
Set oDict = CreateObject("Scripting.Dictionary")

'--- Adding items to dictionary
oDict.Add "One", "Engine"
oDict.Add "Two", "Wheel"
oDict.Add "Three", "Tire"
oDict.Add "Four", "Spanner"

'--- Looping the Collection
For Each vKey In oDict
sItem = oDict.Item(vKey)
'sMsg = sMsg & sItem & vbCrLf
Next

'WScript.Echo (oDict.Count)
'oDict.Item("one") = "temp"
'WScript.Echo sMsg

'wscript.Echo (odict.item(one))
oDict.Key("One") = "nine"
'oDict.Item("nine") = "nine"
oDict.Add "Ten", "ten"

For Each vKey In oDict
sItem = oDict.Item(vKey)
sMsg = sMsg & sItem & " - " &vKey & vbCrLf
Next

WScript.Echo sMsg

WScript.Echo "===============Again============="

WScript.Echo (oDict.Exists ("One"))
WScript.Echo (oDict.Exists ("nine"))
WScript.Echo (oDict.Exists ("Ten"))

'WScript.Echo (odict.item(One))1
'WScript.Echo (odict.item(nine))
'WScript.Echo (odict.item(Ten))

For Each vKey In oDict
sItem = oDict.Item(vKey)
WScript.Echo (sItem & " - " & vKey)
Next

If oDict.Exists("One") Then
WScript.Echo "heello"
End If


If oDict.Exists("nine") Then
WScript.Echo "heello"
End If

Dim temp()
Dim count, counter
count = oDict.Count
WScript.Echo (count)

WScript.Echo
ReDim temp(count)
counter = 0
For Each key In oDict
temp(counter) = key
' WScript.Echo key & " - " & counter
' WScript.Echo temp(counter)
counter = counter+1
Next


'WScript.Echo ("oDict.Keys")

No comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | JCpenney Printable Coupons