?
Solved

How to implement _NewEnum with VB

Posted on 2002-07-24
12
Medium Priority
?
816 Views
Last Modified: 2010-05-18
Hi there.

Is it possible to create a class that implementes its own NewEnum-Interface(for...each), WITHOUT using a collection?

If so, how?
I deposit 50 points for a "no", and will raise to 250 if there is a solution in sight.

tx, holli
0
Comment
Question by:holli
[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
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 5

Expert Comment

by:bob_online
ID: 7175118
I don't think so.  The For Each construction exist for iterating through a members of a collection.  If the members are not in a collection, what are they in?  If they're in an array, you can for use For lowerbound to upperbound.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7175421
I am with bob, excellent explanation by the way :)
0
 
LVL 4

Expert Comment

by:Nazdor
ID: 7177239
You can use For..Each for variables other than Collections, eg:

dim a(20) as string
dim v as variant
for each v in a
   ...
next

But the 'v' must be a variant.

I don't know how you could use this with regard to a NewEnum entry, because you can't do:

   a.[_NewEnum]

but the above might help find an alternative solution, eg, expose the array directly (read-only), as in:

   for each v in myclass.a
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Author Comment

by:holli
ID: 7177407
hi nazdor,

this is a nice one.
it does not answer the question, but i will deposit 50 points for you in this ta.

I believe, to do what i want i have to implement the original collections interface (or parts of it).
this is somewhat hardcore so i`ll pay 300 points for the way to do.


holli
0
 
LVL 4

Accepted Solution

by:
Nazdor earned 200 total points
ID: 7177581
I suspect you might have to look elsewhere than in VB (might be wrong though).  

For example, you can't "Implements Collection" as the collection has _NewEnum method which can't be implemented.


When you say "without using a collection" - do you mean without using a collection of sub-objects?  As in:

clsQuestions
clsQuestion

Where clsQuestions is a collection wrapper for clsQuestion.


If this is what you're trying to get away from, then you could alway just use a generic "collection" within the main class and add whatever you want to it - eg strings, numbers.

Depends on what you're trying to do...
0
 
LVL 6

Author Comment

by:holli
ID: 7178413
"For example, you can't "Implements Collection" as the collection has _NewEnum method which can't be implemented."

Sure you can. If you would know the collections` interface (or better the interface of the collection-class) i, you could create a compatible class using "Implements". Any routines using a collection would then also support the new class, including "for...each".

What i want to do:
I created an associative-array class (like a perl hash). This class uses to parallel collections, one for the keys, one for the values.
i now want to replace the keys-collection by an other (faster) data-structure (e.g. an array or binary tree), but i don´t want to loose the "for...each"-capability.

tx,

holli


0
 
LVL 6

Author Comment

by:holli
ID: 7244699
nazdor, would you be so kind and get you 50 points at
so the question can be closed (and this one also?)

tx, holli
0
 
LVL 6

Author Comment

by:holli
ID: 7244701
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7244892
Holli, why did you post another question? just accepting some of nazdor's comment here would be enought.
Cheers
0
 
LVL 4

Expert Comment

by:Nazdor
ID: 7246826
Sorry for the delay.

Given Richie's comment, I've (now) not added anything to the other question as I'm lead to believe it's easier to get it deleted if there's no comments.

If you still want me to have the points, just let me know.
0
 
LVL 6

Author Comment

by:holli
ID: 7253593
So shall it be.
0
 

Expert Comment

by:iainshepherd
ID: 8566569
For the benefit of anyone (like me) who was looking for this,
Bruce McKinney has the answer.
http://www.mvps.org/vb/hardcore/html/enumeratingvariants.htm

And it's messy. Very messy...
0

Featured Post

Industry Leaders: 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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…
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 Month10 days, 10 hours left to enroll

764 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