Difference between revisions of "Using For Next on your own class"

From HashVB
Jump to: navigation, search
(How to use NewEnum)
 
m (VB6 header)
Line 1: Line 1:
 +
{{VB6}}
 
When doing Object Orientated programming in VB (Yeah, you can stop laughing now :o), it is normally useful to be able to use the For Next construct on your own collection classes.
 
When doing Object Orientated programming in VB (Yeah, you can stop laughing now :o), it is normally useful to be able to use the For Next construct on your own collection classes.
  

Revision as of 22:36, 20 May 2006

float
 This article is based on Visual Basic 6. Find other Visual Basic 6 articles.

When doing Object Orientated programming in VB (Yeah, you can stop laughing now :o), it is normally useful to be able to use the For Next construct on your own collection classes.

Normally this is used when wrapping a collection in type specific code. The following snippet exposes the NewEnum method of the wrapped collection:

Public Property Get NewEnum() As IUnknown
  Set NewEnum = PrivateCollection.[_NewEnum]
End Property

Unfortunately, this will not work on its own, and you need to go into Procedure attributes (on the tools menu) and set the Procedure ID to -4. Optionally, you can also set it to be hidden.