【问题标题】:dictionary of class instances, how to assign new value?类实例字典,如何分配新值?
【发布时间】:2013-05-05 15:31:37
【问题描述】:

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

例如

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

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

【问题讨论】:

    标签: excel dictionary vba


    【解决方案1】:

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

    Set dictionaryP (keyValue) = t
    

    【讨论】:

    • 非常感谢!我自己应该想到的:)
    猜你喜欢
    • 2017-02-05
    • 2013-11-09
    • 2018-10-24
    • 1970-01-01
    • 2014-03-17
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多