I'm new to programming so I'm sorry if my question seems dumb. I want to ask if there is any way to return the keys from Multi.Dictionary
when I have the value?
This is my code:
Dim myDict
Set myDict= Server.CreateObject("Multi.Dictionary")
myDict.UniqueKeys = False
'Fill dictionary with some data
myDict("param1") = "value1"
myDict.Add "param2", "value2"
myDict.Add "param2", "value2.2"
'Get dictionary Keys
Keys = myDict.Keys
Items = myDict.Items
For Z = 0 To UBound(Items)
Response.Write(Keys(Z) & " " & Items(Z) & "<br>")
Next
And for now returns
Subscript out of range: '2'
Which is normal because I loop 3 times while I have only 2 keys.
So is it possible to have a result like this:
Param1: "value1" Param2: "value2" Param2: "value2.2"
You can loop through the keys of myDict
by checking the items multiple or not.
Dim myDict
Set myDict= Server.CreateObject("Multi.Dictionary")
myDict.UniqueKeys = False
myDict("param1") = "value1"
myDict.Add "param2", "value2"
myDict.Add "param2", "value2.2"
Dim key, subItem
For Each key In myDict.Keys
If IsArray(myDict(key)) Then ' item is an array
For Each subItem In myDict(key)
Response.Write key & ": " & subItem & "<br>"
Next
Else
Response.Write key & ": " & myDict(key) & "<br>"
End If
Next
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With