Solved

Iterating user collections

Posted on 1998-11-25
3
198 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

831 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