Solved

How to implement _NewEnum with VB

Posted on 2002-07-24
12
808 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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
 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

805 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