Reputation: 2548
I have a dictionary that contains instances of a class. Somehow i can not find a way to change a value (assign new class instance) to dictionary.
For example
Dim t as new Product
'initialize t
if dictionaryP.Exists(keyValue) then
'in the next line i get an error "Object doesn't support this property or method"
dictionaryP.Item(keyValue)=t
else
'no problem with this line...
dictionaryP.Add keyValue, t
end if
Couldn't find any information about using dictionaries in VBA with values that are objects, not just plain strings or integers. How can i change dictionary value for dictionaries that stores objects (class instances), as it seems that i can not do it using
dictionary.Item(key) = <new Object value> ' as i thought it sould be, from this source
What am i missing? How can i change dictionary values, if values are objects (not plain values)?
Upvotes: 2
Views: 5795
Reputation: 13713
Objects must be assigned using Set
. The property .Item
is the default property and can therefore be dropped (but does not harm). Try
Set dictionaryP (keyValue) = t
Upvotes: 5