excel - 类实例的字典,如何分配新值?

标签 excel dictionary vba

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

例如

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

我错过了什么?如果值是对象(不是普通值),我如何更改字典值?

最佳答案

对象必须使用Set来分配。属性 .Item 是默认属性,因此可以删除(但不会造成损害)。尝试一下

Set dictionaryP (keyValue) = t

关于excel - 类实例的字典,如何分配新值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16386085/

相关文章:

vba - 数据透视表错误 1004

javascript - ECMAScript 6 Map & Set - 在迭代过程中可以安全删除吗?

c# - 将数据从 Microsoft SQL Server 数据库发送到 JavaScript 函数的最佳方式

html - 使用值而不是索引从 HTML 下拉列表中选择的 VBA 代码

Excel VBA循环并以交互方式显示更改

c# - 预测 Excel 如何使用 Postgres 函数解释字符串

vba - 使用 Excel VBA 比较列并突出显示匹配数据

python - 如何加速 pandas drop() 方法?

vba - 用 Excel 和 VBA 在字符串中查找?

Python 用字典值替换字符串