|
-
Jan 8th, 2004, 01:54 PM
#1
Thread Starter
Addicted Member
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?
-
Jan 8th, 2004, 02:48 PM
#2
Ah, this is where it becomes a little more convoluted. Have a look at http://peisker.de/index.html?http://...e/vb/lists.htm
-
Jan 8th, 2004, 06:23 PM
#3
Addicted Member
Code:
Friend Enum myEnums
value1
value2
value3
End Enum
You mean like this?
-
Jan 9th, 2004, 09:09 AM
#4
Thread Starter
Addicted Member
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
-
Jan 9th, 2004, 09:14 AM
#5
Fanatic Member
you can just create a collection of objects from your class can't you?
-
Jan 9th, 2004, 09:16 AM
#6
Thread Starter
Addicted Member
-
Jan 9th, 2004, 09:28 AM
#7
Fanatic Member
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
-
Jan 9th, 2004, 10:13 AM
#8
Thread Starter
Addicted Member
no that's not what i mean. i will give you an example in Vb6 of what I want to do:
Vb6:
VB Code:
Class Test
Private p_Collection as Collection
Sub Add(o)
p_Collection.Add(o)
End Sub
Public Property Test() As IUnknown
Test = p_Collection.[_NewEnum]
End Property
End Class
Public Class TestChild
Public Var1 As String
End Class
Form1:
Dim X As New Test
Dim Child As New TestChild
X.Add(Child)
' This is what I want to do in .NET
' using my own classes
For Each Child In Test
Msgbox Child.Var1
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..."
-
Jan 9th, 2004, 10:29 AM
#9
Fanatic Member
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
-
Jan 9th, 2004, 03:56 PM
#10
Frenzied Member
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
-
Jan 9th, 2004, 03:56 PM
#11
Frenzied Member
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
-
Jan 10th, 2004, 08:49 AM
#12
Thread Starter
Addicted Member
maybe. i dont know. can you give me an example?
-
Jan 10th, 2004, 02:43 PM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|