Solved

Iterating user collections

Posted on 1998-11-25
3
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month5 days, 19 hours left to enroll

627 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