Exposing an enumerable class to VB6

ikantspelwurdz

Well-known member
Joined
Dec 8, 2009
Messages
49
Programming Experience
1-3
I have a VB.NET class that looks like this:

VB.NET:
Public Interface IBottles
    Inherits IEnumerable

End Interface

Public Class Bottles
    Implements IBottles

    Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
        Dim bottles As New List(Of String)
        bottles.Add("10 bottles of beer on the wall")
        bottles.Add("9 bottles of beer on the wall")
        bottles.Add("8 bottles of beer on the wall")
        bottles.Add("7 bottles of beer on the wall")
        bottles.Add("6 bottles of beer on the wall")
        bottles.Add("5 bottles of beer on the wall")
        bottles.Add("4 bottles of beer on the wall")
        bottles.Add("3 bottles of beer on the wall")
        bottles.Add("2 bottles of beer on the wall")
        bottles.Add("1 bottle of beer on the wall")
        Return bottles.GetEnumerator
    End Function
End Class
This VB.NET program works fine:
VB.NET:
    Sub Main()
        Dim bottles As New Bottles
        For Each b As String In bottles
            Console.WriteLine(b)
        Next
        Console.ReadLine()
    End Sub
The goal, however, is to make the class work in this VB6 code:
VB.NET:
Private Sub Form_Load()
    Dim tb As IBottles
    Set tb = New Bottles
    
    Dim b As Object
    For Each b In tb
        'Output contents of b
    Next

End Sub
The above code crashes on the For Each loop with "Object doesn't support this property or method."

What do I need to do to the Bottles class to make the VB6 code work?
 
Top Bottom