Excel vba: Property let procedure not defined and property get procedure did not return an object

前端 未结 3 1519
广开言路
广开言路 2021-01-23 12:02

I have a Client class. Inside that class there is an array losses. First I create and populate with clients a clientsColl array. Then for

3条回答
  •  鱼传尺愫
    2021-01-23 12:27

    To conclude what was said in comments:

    Your problem (error 451) often occures when you trying to compound properties. To represent this case we can use any structure of any object with properties.

    Let's emulate it with array of collections:

    Option Explicit
    
    Sub Test()
        Dim Arr As Variant
        Dim Col As Collection
        Dim i As Long
        Dim j As Long
    
        ReDim Arr(1 To 10)
    
        For i = 1 To 10
            Set Col = New Collection
            For j = 1 To 10
                Call Col.Add(j)
            Next
    
            Set Arr(i) = Col
        Next
    
        On Error Resume Next
        Debug.Print Arr(1).Item(1)
        Debug.Print Arr(1).Item()(1)
        On Error GoTo 0
    End Sub
    

    Your problem stems from the fact that you're treating your properties as attributes. On not-so-compounded (or when your array is declared explicitly as array of class instances) level it works due to early binding. But when things start to get more complex - it's fail, since your property just another function.

    Hence, to achieve what you want, you should call it explicitly with another pair of parentheses.

提交回复
热议问题