我想将字典对象存储在数组中,但是我收到错误。有什么办法可以在数组中存储字典
Sub aaa()
Dim arr(5)
'arr(0) = 100
Set dict_123 = CreateObject("Scripting.Dictionary")
dict_123.Add "first", 300
dict_123.Add "Second", 500
arr(0) = dict_123
End Sub
错误是错误的参数数量或无效的属性赋值在" arr(0)= dict_123"
答案 0 :(得分:1)
尝试以下
Option Explicit
检查变量声明Object
set
关键字
醇>
<强>代码:强>
Option Explicit
Public Sub aaa()
Dim arr(5)
Dim dict_123 As Object
Set dict_123 = CreateObject("Scripting.Dictionary")
dict_123.Add "first", 300
dict_123.Add "Second", 500
Set arr(0) = dict_123
End Sub
修改强>
作为功能
Option Explicit
Public Sub DoSomeThing()
Dim dict As Object
Set dict = aaa()(0)
Dim key As Variant
For Each key In dict.Keys
Debug.Print dict(key)
Next key
End Sub
Public Function aaa() As Variant
Dim arr(5)
Dim dict_123 As Object
Set dict_123 = CreateObject("Scripting.Dictionary")
dict_123.Add "first", 300
dict_123.Add "Second", 500
Set arr(0) = dict_123
aaa = arr
End Function