I've been getting a
wrong number of argument or invalid property assignment collection
error for a long time now, but can't figure out what's wrong. I have a class and a Collection inside that class and a Sub to add values to that collection.
Private sumLosses As Collection
Private Sub Class_Initialize()
Set sumLosses = New Collection
End Sub
Public Property Get getSumLosses()
getSumLosses = sumLosses
End Property
Inside main module:
For Each clientCopy In clientsColl
clientCopy.getSumLosses.Add 200 'error
clientCopy.getSumLosses.Add (200) 'error
Next
Why does this fail and how do I add the items to a class' collection?
sumLosses is of type Collection therefore it is an object and has to be Set to another variable/function.
With using Set it should work:
Public Property Get getSumLosses() As Collection
Set getSumLosses = sumLosses
End Property
Also defining the property As Collection might be no bad idea (but this didn't cause the error).
You need to declare Public Property Get getSumLosses() as a Collection and use Set :
Private sumLosses As Collection
Private Sub Class_Initialize()
Set sumLosses = New Collection
End Sub
Public Property Get getSumLosses() as Collection
Set getSumLosses = sumLosses
End Property
:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With