繁体   English   中英

通过VB6字典迭代

[英]Iterate through a VB6 Dictionary

我是一个非VB6的人,不幸遗传了一个有缺陷的传统VB6 / Classic ASP项目。 有一个部分,很多条目被放入一个Dictionary ,我希望看到它包含的所有条目。 我试过这个( oParams是一个字典):

Dim o As Object
Dim sDicTempAggr As String
sDicTempAggr = ""
For Each o In oParams
    sDicTempAggr = sDicTempAggr & ", " & o
Next

返回的是:

Object不支持此属性或方法:438

使用Option Explicit ,如何遍历VB6 Dictionary以查找它包含的所有内容?

这是一个迭代的示例,如果你还有问题,请查看第二个循环来检查字典中值的类型

  Dim oParams As New Dictionary
    oParams.Add 1, "This"
    oParams.Add 2, "That"
    oParams.Add 3, "The other"
    Dim key As Variant
    Dim sDicTempAggr  As String
    Dim sTypes As String
    For Each key In oParams.Keys
        sDicTempAggr = sDicTempAggr & IIf(sDicTempAggr <> "", ",", "") & oParams(key)
    Next key
    For Each key In oParams.Keys
          sTypes = sTypes & IIf(sTypes <> "", ",", "") & TypeName(oParams(key))
    Next key

对Dictionary的枚举不是Object类型,您应该使用Variant

Dim o As Variant
Dim sDicTempAggr As String
sDicTempAggr = ""

For Each o In oParams
    sDicTempAggr = sDicTempAggr & ", " & oParams(o)
Next

同样在For Each ,Key不返回字典成员,因此返回值为oParams(o) ,如果更改为For Each o In oParams.items您可以直接使用oParams

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM