Prokurors
Prokurors

Reputation: 2548

dictionary of class instances, how to assign new value?

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

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/A_3391-Using-the-Dictionary-Class-in-VBA.html

What am i missing? How can i change dictionary values, if values are objects (not plain values)?

Upvotes: 2

Views: 5795

Answers (1)

JohnB
JohnB

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

Related Questions