2013-05-05 133 views
0

我有一个包含一个类的实例的字典。不知何故,我无法找到一种方法来改变一个值(分配新的类实例)到字典。类实例字典,如何分配新值?

例如

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 

找不到任何关于使用字典中VBA 与那些对象,不只是简单的字符串或整数值的任何信息。 我如何更改字典存储对象(类实例)的字典价值,因为它似乎我不能使用

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

我缺少做呢?如果值是对象(不是简单的值),我该如何更改字典值?

回答

2

必须使用Set分配对象。属性.Item是默认属性,因此可以丢弃(但不会造成伤害)。尝试

Set dictionaryP (keyValue) = t 
+0

非常感谢!应该自己想过:) – Prokurors 2013-05-05 15:39:10