Unable to create New Enum in VBA

前端 未结 1 1637
日久生厌
日久生厌 2021-01-12 06:42

I am creating an Immutable Linked List class in VBA. It provides ToArray and ToCollection methods, which I have both verified as working. However

相关标签:
1条回答
  • 2021-01-12 07:15
    Public Property Get NewEnum() As IUnknown
    Attribute NewEnum.VB_UserMemId = -4
    
        Set NewEnum = ToCollection.[_NewEnum]
    
    End Property
    

    ToCollection is returning a new collection every time it's called; this would probably work:

    Public Property Get NewEnum() As IUnknown
    Attribute NewEnum.VB_UserMemId = -4
    
        Static internalCollection As Collection
        If internalCollection Is Nothing Then Set internalCollection = ToCollection
    
        Set NewEnum = internalCollection.[_NewEnum]
    
    End Property
    

    ...but it's rather ugly. Ideally you'd have some instance-level encapsulated As Collection to return the [_NewEnum] value from.

    0 讨论(0)
提交回复
热议问题