Solved

Iterating user collections

Posted on 1998-11-25
3
199 Views
Last Modified: 2010-05-03
I have a class Chair in my system. Now I want to deal with typed collections of chairs, so I have defined a ColChair class, with a collection-like interface: Add, Remove, Item and Count. I have made Item the defaut property. The problem is I can't iterate the collection with a "For Each" construct; it crashes at run-time:

  Dim col As New ColChair
  'fill col with Chair objects.
  Dim ch As Chair
  For Each ch In col 'this line crashes.
    'do something with ch.
  Next ch

Any ideas?.

Regards,
César.
0
Comment
Question by:CesarGon
3 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1446794
What error to you get?
0
 

Accepted Solution

by:
Belgarion_aus earned 100 total points
ID: 1446795
Add the following method to your collection class:

Public function NewEnum() as IUnknown
   
    Set NewEnum = mycollection.[_NewEnum]

End Function

Yes, the square brackets [] MUST be there !

Now go to tools/Procedure Attributes

In the name box select the NewEnum Method,

click advanced and select hide this member,

In Procedure Id box type -4. -4 is the procedure ID that implements For Each....Next.

And your done! Now For Each....Next will work.


0
 
LVL 3

Author Comment

by:CesarGon
ID: 1446796
Thanks for your reply. It really works!. To satisfy my curiosity, please may you tell me where you learnt the solution?.

Regards,
César.

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question