VBA 将类添加到集合 [英] VBA Adding a class to a collection

查看:55
本文介绍了VBA 将类添加到集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Holding 的类模块.其中有几个公共变量.我的代码是这样的:

I have a class module called Holding. In it are several public variables. My code is this:

Dim holdings as Collection
Dim h as Holding

Set holdings = new Collection

For i = 1 to last
    Set h = new Holding

    h.x = y
    '... etc

    holdings.Add(h)
Next i

这给了我 holdings.Add(h) 行上的错误对象不支持此属性或方法",但在我看到的任何地方,它都给出了如何实现这一点的确切示例.我错过了什么?

This gives me error "object doesnt support this property or method" on the holdings.Add(h) line, but everywhere I look, it gives this exact example of how to achieve this. What am I missing?

推荐答案

去掉括号.

holdings.Add h

否则,您正在尝试将 Holding 实例的默认属性的值添加到集合中,但它没有默认属性.

Otherwise you are trying to add to the collection the value of the default property of your Holding instance, and it doesn't have a default property.

这篇关于VBA 将类添加到集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆