在VBA中为对象设置集合属性

lak*_*esh 2 vba class

我有一个集合作为财产,

债券类

Private pBondiSIN As String
Private pBroker As Collection

''''''''''''''''''''''
' BondiSIN property
''''''''''''''''''''''
Public Property Get BondiSIN() As String
    BondiSIN = pBondiSIN
End Property
Public Property Let BondiSIN(Value As String)
    pBondiSIN = Value
End Property

''''''''''''''''''''''
' Broker property
''''''''''''''''''''''
Public Property Get Broker() As Collection
    Broker = pBroker
End Property
Public Property Let Broker(Value As Collection)
    pBroker = Value
End Property
Run Code Online (Sandbox Code Playgroud)

我这样称呼它:

Set tempBond = New Bond
tempBond.Broker = New Collection  => Gives me a error as Wrong number of Arguments or Invalid property assignment
Run Code Online (Sandbox Code Playgroud)

不知道如何解决这个错误.需要一些帮助.

小智 5

熟悉Set关键字

Public Property Set Broker(Value As Collection)
    Set pBroker = Value
End Property
Run Code Online (Sandbox Code Playgroud)

Set tempBond.Broker = New Collection
Run Code Online (Sandbox Code Playgroud)