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

I'm new to programming, so I'm sorry if my question seems dumb. I want to ask, is there a way to return keys from Multi.Dictionarywhen I have a 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 now returns

Subtitle out of range: '2'

This is normal because I loop 3 times, so far I only have 2 keys.

So, you can get this result:

Param1: "value1"
Param2: "value2" 
Param2: "value2.2"
+4
source share
1 answer

You can scroll through the keys myDict, checking a few items 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
+1
source

Source: https://habr.com/ru/post/1627765/


All Articles