dictionary - 如何访问VBscript字典中的数组项
问题描述
我在 UFT (VBScript) 中有一个字典对象,其中包含数组项。我想知道如何遍历该数组项中键引用的每个元素。下面是我的字典中包含数组项的示例
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"))
由于这个字典是动态生成的,我不确定它在数组中有多少元素。现在我需要遍历数组中的所有元素以找到我需要的元素例如。如何遍历节点名(键)数组中的所有元素,直到找到 EMS。我尝试了不同的访问方式,但没有成功。
请帮我解决。
解决方案
要检查是否在为 key 存储的数组中找到“EMS” Nodename
,您可以检查以下代码:
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
推荐阅读
- swift - UIButton 系统样式选中状态,保留图片和背景
- java - JSP Maven 项目不会在 Eclipse 中包含 src 文件夹
- ssl - 在 Domain.com 上设置 SSL
- django - 如何在 django import-export 的导出上添加页眉/页脚?
- php - 我应该将逻辑放在 Laravel 中的哪里来解开请求并更新模型?
- c# - 如何让 HTML Agility 针对 Windows 集成安全应用进行身份验证?
- python - 如何在powershell命令中将类似dict的字符串作为python参数发送
- sql - 两个查询返回不同的数据
- laravel - Laravel 多对多多主键与枢轴
- vba - 确认 Adobe 通知以使用 VBA 打开损坏的 PDF