开发者

VBA Adding a class to a collection [duplicate]

开发者 https://www.devze.com 2023-03-13 02:55 出处:网络
This question already has answers here: VB6 pass by value and pass by reference (2 answers) Closed 1 year ago.
This question already has answers here: VB6 pass by value and pass by reference (2 answers) Closed 1 year ago.

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

Dim holdings as Collection
Dim h as Hold开发者_高级运维ing

Set holdings = new Collection

For i = 1 to last
    Set h = new Holding

    h.x = y
    '... etc

    holdings.Add(h)
Next i

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?


Remove the parentheses.

holdings.Add h

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消