Results 1 to 13 of 13

Thread: NewEnum in VB.NET?

  1. #1

    Thread Starter
    Addicted Member danielkw's Avatar
    Join Date
    Mar 2000
    Location
    Sweden
    Posts
    134

    NewEnum in VB.NET?

    In VB6 you can create your own enumerators by creating a function like this:
    function Enumerator() as IUNKnown
    Enumerator = col.[_NewEnum]
    end function

    how do I do this in VB.NET?

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Ah, this is where it becomes a little more convoluted. Have a look at http://peisker.de/index.html?http://...e/vb/lists.htm

  3. #3
    Addicted Member
    Join Date
    Aug 1999
    Posts
    164
    Code:
    Friend Enum myEnums
        value1
        value2
        value3
    End Enum
    You mean like this?
    -Shurijo

  4. #4

    Thread Starter
    Addicted Member danielkw's Avatar
    Join Date
    Mar 2000
    Location
    Sweden
    Posts
    134
    no I don't mean creating those enumerators. what i am talking about is creating the ability to enumerate my own classes, like:

    dim ChildClass as Child
    for each ChildClass In MyOwnClass
    ...
    next

  5. #5
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    you can just create a collection of objects from your class can't you?
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  6. #6

    Thread Starter
    Addicted Member danielkw's Avatar
    Join Date
    Mar 2000
    Location
    Sweden
    Posts
    134
    how?

  7. #7
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    Code:
            
            Dim myChild1 As New Child()
            Dim myChild2 As New Child()
            Dim myCollection As New System.Collections.ArrayList()
    
            myCollection.Add(myChild1)
            myCollection.Add(myChild2)
    
            Dim tempChild As Child
            For Each tempChild In myCollection
                MsgBox(tempChild.name)
            Next
    
        
        Public Class Child
            Public name As String = "Nick"
        End Class
    i don't know if this is wot you mean?

    Hope it helps
    Nick
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  8. #8

    Thread Starter
    Addicted Member danielkw's Avatar
    Join Date
    Mar 2000
    Location
    Sweden
    Posts
    134
    no that's not what i mean. i will give you an example in Vb6 of what I want to do:
    Vb6:
    VB Code:
    1. Class Test
    2.     Private p_Collection as Collection
    3.     Sub Add(o)
    4.         p_Collection.Add(o)
    5.     End Sub
    6.     Public Property Test() As IUnknown
    7.         Test = p_Collection.[_NewEnum]
    8.     End Property
    9. End Class
    10.  
    11. Public Class TestChild
    12.     Public Var1 As String
    13. End Class
    14.  
    15. Form1:
    16. Dim X As New Test
    17. Dim Child As New TestChild
    18. X.Add(Child)
    19.  
    20. ' This is what I want to do in .NET
    21. ' using my own classes
    22. For Each Child In Test
    23.     Msgbox Child.Var1
    24. Next

    And just to make this even more clear:
    I don't want the solution "Why don't you just make the collection public and access it during the For..Each instead of your class..."

  9. #9
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    go to the original link up the top:
    http://peisker.de/index.html?http://...e/vb/lists.htm

    there is a bit on the second third of the article that should help

    Nick
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  10. #10
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    isn't this a matter of implementing the IEnumerable interface?

    As far as I recall this interface must be implemented if you want to do a

    for each A as B in C

    /Henrik

  11. #11
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    isn't this a matter of implementing the IEnumerable interface?

    As far as I recall this interface must be implemented if you want to do a

    for each A as B in C

    /Henrik

  12. #12

    Thread Starter
    Addicted Member danielkw's Avatar
    Join Date
    Mar 2000
    Location
    Sweden
    Posts
    134
    maybe. i dont know. can you give me an example?

  13. #13
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Originally posted by danielkw
    maybe. i dont know. can you give me an example?
    Perhaps you should read the content on the link I posted

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width