For each Question

  • Thread starter Thread starter Scott Meddows
  • Start date Start date
S

Scott Meddows

How do I write an interface to a class that represents a group of objects
like I would the controls object?

i.e.

I want to do this....

Dim simpleObject as new MyObjectGroup
Dim anObject as AnObjectInTheGroup

For each anObject in simpleObject
' Blah
Next

I remember in VB 6 (pauses for cringes), you implemented a COM interface.
How do you do this in .NET?

Thanks

Scott
 
here's a simple example: (since everything is an object in .net, you don't
have to use variant enumeration but can strong type it instead)

'=============================================

sub main()
dim p as new parent
dim c as child
for each c in p.children
console.writeline("Index: " & c.index)
next
end sub

class parent

private myKids() as child

sub new()
redim myKids(2)
dim i as integer
for i = 0 to 2
myKids(i) = new child(i)
next
end sub

readonly property children() as child()
get
return myKids()
end get
end property

end class

class child

private myIndex as integer

sub new(byval index as integer)
myIndex = index
end sub

readonly property index() as integer
get
myIndex
end get
end property

end class

'=============================================

hth,

steve
 
Will this work on an arraylist also?

steve said:
here's a simple example: (since everything is an object in .net, you don't
have to use variant enumeration but can strong type it instead)

'=============================================

sub main()
dim p as new parent
dim c as child
for each c in p.children
console.writeline("Index: " & c.index)
next
end sub

class parent

private myKids() as child

sub new()
redim myKids(2)
dim i as integer
for i = 0 to 2
myKids(i) = new child(i)
next
end sub

readonly property children() as child()
get
return myKids()
end get
end property

end class

class child

private myIndex as integer

sub new(byval index as integer)
myIndex = index
end sub

readonly property index() as integer
get
myIndex
end get
end property

end class

'=============================================

hth,

steve
 
you mean just a list of text or whatever?

yes, you can make a property that returns a simple one dimensional array of
*any* object type and enumerate it to death.
 
Thanks, Herfried.

But I have option strict on and I'm having a hard time implementing the
class.. This is what I have.

Class POs

Private m_pos as ArrayList ' this object holds a list of PO objects

... Code here
End Class

Class PO

... Code here
End Class

Where do I need to implement the interfaces in here? This is what I'm liek
to do.

Dim allPOs as new POs
Dim CurrentPO as PO
For each CurrentPO in allPO
'Blah
next
 
Scott Meddows said:
Thanks, Herfried.

But I have option strict on and I'm having a hard time implementing
the class.. This is what I have.

Class POs

Private m_pos as ArrayList ' this object holds a list of PO
objects

... Code here
End Class

Class PO

... Code here
End Class

Where do I need to implement the interfaces in here?

Class POs
Implements IEnumerable

Private m_pos as ArrayList ' this object holds a list of PO objects

... Code here
Public Function GetEnumerator() As System.Collections.IEnumerator _
Implements System.Collections.IEnumerable.GetEnumerator

return m_pos.getenumerator
End Function


End Class
 
Nevermind, thanks, though.

I don't quite understand the code, but with some "code dancing" I was able
to implement it.

Thanks a lot.
 
PERFECT SOLUTION!

Thanks, Armin.

Armin Zingler said:
Class POs
Implements IEnumerable

Private m_pos as ArrayList ' this object holds a list of PO objects

... Code here
Public Function GetEnumerator() As System.Collections.IEnumerator _
Implements System.Collections.IEnumerable.GetEnumerator

return m_pos.getenumerator
End Function


End Class
 
Back
Top