Solved

How to implement _NewEnum with VB

Posted on 2002-07-24
12
806 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
  • 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
 
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 50 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

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

15 Experts available now in Live!

Get 1:1 Help Now