Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show keys in a Motobit Multi.Dictionary by the given item value?

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"
like image 203
nyagolova Avatar asked Nov 08 '22 20:11

nyagolova


1 Answers

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
like image 118
Kul-Tigin Avatar answered Nov 15 '22 05:11

Kul-Tigin