Solved

Iterating user collections

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now