如何通过给定的项目值在 Motobit Multi.Dictionary 中显示密钥?
How to show keys in a Motobit Multi.Dictionary by the given item value?
我是编程新手,如果我的问题看起来很愚蠢,我很抱歉。我想问有没有办法在我有值的时候return来自Multi.Dictionary
的键?
这是我的代码:
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
现在 returns
Subscript out of range: '2'
这是正常的,因为我只有 2 个键时循环了 3 次。
那么有没有可能得到这样的结果:
Param1: "value1"
Param2: "value2"
Param2: "value2.2"
您可以通过检查项目是否多个来遍历 myDict
的键。
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
我是编程新手,如果我的问题看起来很愚蠢,我很抱歉。我想问有没有办法在我有值的时候return来自Multi.Dictionary
的键?
这是我的代码:
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
现在 returns
Subscript out of range: '2'
这是正常的,因为我只有 2 个键时循环了 3 次。
那么有没有可能得到这样的结果:
Param1: "value1" Param2: "value2" Param2: "value2.2"
您可以通过检查项目是否多个来遍历 myDict
的键。
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