Reputation: 2945
I want to set a dictionary as dictionary value? But it throws an error like
'Wrong number of arguments or invalid property assignment'.
How to fix this issue?
sub test()
Dim Dict As Scripting.Dictionary
Set Dict = New Scripting.Dictionary
Dim rows As Scripting.Dictionary
Set rows = New Scripting.Dictionary
dict("name") = "Sarah"
dict("surname") = "Jones"
rows(dict("name")) = dict
end sub
Upvotes: 2
Views: 1533
Reputation: 71177
Dictionary
is an object type, with a default member.
rows(dict("name")) = dict
The RHS of this assignment is really a call to dict.Item
, but invoked without any parameters... but the Key
parameter is required - hence the error.
The Set
keyword disambiguates default member calls from "yes I really mean the object reference itself"
Set rows(dict("name")) = dict
Upvotes: 4