【发布时间】:2015-11-17 20:31:24
【问题描述】:
我有一个名为 flArr 的数组,我将其传输到字典并测试另一个数组中的元素(如果存在),然后我将其添加到列表框中,但我不知道,不知何故它无法正常工作给我“需要对象”错误。有什么想法吗?。
Set dic_cc = CreateObject("scripting.dictionary")
dic_cc = flArr 'transferring array to dictionary
For Each f In heArr 'another array heArr
If dic_cc.Exists(f) Then Me.FilterList.AddItem f
Next
谢谢
【问题讨论】:
-
您不能将数组分配给这样的字典 - 您需要遍历数组并逐个添加项目。
-
是的,我可以。我可以遍历 dic_cc 并且我看到了该数组的所有元素。我在这一行只有问题 If dic_cc.Exists(f) Then Me.FilterList.AddItem f
-
不,你不能。尝试声明 dic_cc
As Object看看会发生什么。您在当前代码中所做的是将变量dic_cc分配给数组flArr- 此时它不再是 Dictionary 对象并变成数组。仅当您将 dic_cc 声明为 Variant(或至少不是Object)时才有效。
标签: arrays vba dictionary