Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to implement _NewEnum with VB

Posted on 2002-07-24
12
Medium Priority
?
818 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
Suggested Courses

604 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