-
How to implement For Each Loop in Collection
Is there anyone who can give me a sample of implementing For Each Loop on
User created Collection?
Thanks
Sameers
Sameers@theangrycoder.com
-
Re: How to implement For Each Loop in Collection
On 18 Dec 2001 21:25:12 GMT, "sameers" <sameers@theangrycoder.com> wrote:
¤
¤ Is there anyone who can give me a sample of implementing For Each Loop on
¤ User created Collection?
¤
Relatively simply example:
Dim col As New Collection
Dim vItem As Variant
col.Add "Test"
col.Add "Another Test"
col.Add "Yet Another Test"
For Each vItem In col
Debug.Print vItem
Next
Set col = Nothing
Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
-
Re: How to implement For Each Loop in Collection
Hi Sameer,
You need to implement a Public Function in your Collection Class like as
below
________
' NewEnum must return the IUnknown interface of a
' collection's enumerator.
Public Function NewEnum() As IUnknown
Set NewEnum = m_colObjects.[_NewEnum]
End Function
___________
where m_colObjects is your private collection class object declared as
___________
Private m_colObjects as Collection
___________
And hide the NewEnum method and give it a procedure ID -4
To do that, go to Tools menu, click Procedure Attributes to open the Procedure
Attributes dialog box. In Name box, select the NewEnum method.
Click Advanced to show the advanced features. Check Hide this member to make
NewEnum hidden in the type library.
In the Procedure ID box, type –4 (minus four) to give NewEnum the procedure
ID required by For Each ... Next. Click OK.
Now you collection class will be capable of providing For Each ... Next
functionality.
HTH,
Raghu.
Paul Clement <UseAdddressAtEndofMessage@swspectrum.com> wrote:
>On 18 Dec 2001 21:25:12 GMT, "sameers" <sameers@theangrycoder.com> wrote:
>
>¤
>¤ Is there anyone who can give me a sample of implementing For Each Loop
on
>¤ User created Collection?
>¤
>
>Relatively simply example:
>
>Dim col As New Collection
>Dim vItem As Variant
>
>col.Add "Test"
>col.Add "Another Test"
>col.Add "Yet Another Test"
>
>For Each vItem In col
> Debug.Print vItem
>Next
>
>Set col = Nothing
>
>
>Paul ~~~ pclement@ameritech.net
>Microsoft MVP (Visual Basic)
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks