我有一本包含类实例的字典。不知何故,我找不到一种方法来更改字典的值(分配新的类实例)。
例如
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
我错过了什么?如果值是对象(不是普通值),我如何更改字典值?
最佳答案
对象必须使用Set
来分配。属性 .Item
是默认属性,因此可以删除(但不会造成损害)。尝试一下
Set dictionaryP (keyValue) = t
关于excel - 类实例的字典,如何分配新值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16386085/