2013-05-05 57 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