Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Iterating user collections

Posted on 1998-11-25
3
Medium Priority
?
203 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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

972 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