Dictionary 如何访问VBscript字典中的数组项
我在UFT(VBScript)中有一个dictionary对象,其中包含数组中的项。我想知道如何迭代通过键引用的数组项中的每个元素。 下面是我的字典中包含数组项的示例Dictionary 如何访问VBscript字典中的数组项,dictionary,vbscript,uft14,Dictionary,Vbscript,Uft14,我在UFT(VBScript)中有一个dictionary对象,其中包含数组中的项。我想知道如何迭代通过键引用的数组项中的每个元素。 下面是我的字典中包含数组项的示例 Set NodeValues = CreateObject("Scripting.Dictionary") NodeValues.Add "Nodename", Array("EMS", "ACM") NodeValues.Add "MSW", Array("0x31,0x32,0x33,0x34" , "0x25,0x25,0
Set NodeValues = CreateObject("Scripting.Dictionary")
NodeValues.Add "Nodename", Array("EMS", "ACM")
NodeValues.Add "MSW", Array("0x31,0x32,0x33,0x34" , "0x25,0x25,0x12,0x12")
NodeValues.Add "SBL", Array("0x35,0x32,0x30,0x31" , "0x45,0x55,0x22,0x92")
NodeValues.Add "Data", Array(array("0x21,0x21,0x21", "0x11,0x11,0x22") , array("0x45,0x55,0x22,0x92","0x25,0x65,0x25"))
因为这个字典是动态生成的,所以我不确定它在数组中有多少个元素。现在我需要循环遍历数组中的所有元素,以找到所需的元素
例如如何遍历Nodename(key)数组中的所有元素,直到找到EMS。我尝试了不同的访问方式,但没有成功
请帮助我解决问题。要检查为密钥节点名存储的数组中是否找到“EMS”,可以检查以下代码:
For Each element In NodeValues.Item("Nodename")
If StrComp(element, "EMS", 1) = 0 Then
MsgBox "found"
Exit For
End If
Next
要获取索引,请执行以下操作:
arrTemp = NodeValues.Item("Nodename")
blnFound = False
For i = 0 To UBound(arrTemp)
If StrComp(arrTemp(i), "EMS", 1) = 0 Then
blnFound = True
Exit For
End If
Next
If blnFound Then
MsgBox "Index: " & i
Else
MsgBox "Not found"
End If
谢谢你的快速回复。如何知道EMS在阵列中的索引位置。因此,我需要使用该索引来查找相应数组中的MSW或数据项。例如,如果EMS存储在索引0中,则MSW值也将存储在索引0中,这同样适用于其他。此外,我需要读取MSW中的相应值和EMS的数据,并在其他函数中使用这些值。@SrinivasVenkataram我已更新了答案