79464572

Date: 2025-02-24 19:08:09
Score: 3
Natty:
Report link

I used your great CustomCollection and EnumHelper from your post https://stackoverflow.com/a/65736562/7658533

Then I implemented two test procedures, TestOk and TestOk, both using a function GetCustomCollection to retrieve a CustomCollection instance.

The first procedure TestOk stores the instance in a local variable first, the second TestNotOk uses the instance inline from the functions result.

As you can see, TestNotOk does not iterate any value of the resulting instance.

Do you have a clue how CustomCollection and/or EnumHelper can be reworked to get TestNotOk running properly too?

Public Sub TestOk()
    Dim xCustomCollection As CustomCollection
    Set xCustomCollection = GetCustomCollection()

    Dim xItem As Variant
    For Each xItem In xCustomCollection.NewEnum
        Debug.Print xItem
    Next xItem
End Sub

Public Sub TestNotOk()
    Dim xItem As Variant
    For Each xItem In GetCustomCollection().NewEnum
        Debug.Print xItem
    Next xItem
End Sub

Private Function GetCustomCollection() As CustomCollection
    Set GetCustomCollection = New CustomCollection

    GetCustomCollection.Add 1
    GetCustomCollection.Add 2
End Function
Reasons:
  • Blacklisted phrase (1): stackoverflow
  • RegEx Blacklisted phrase (2.5): Do you have a
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • High reputation (-1):
Posted by: AHeyne