3

I would like to now how the ASP Classic/VB6 FOR EACH loop works. I know with .NET IEnumberable/IEnumerator are involved, but how does VB6/ASP Classic do it?

Thanks!

Ian McShane
  • 340
  • 3
  • 10
  • BTW thanks for this, a real nostalgia trip. http://forums.devx.com/archive/index.php/t-75539.html Was I really discussing this sort of stuff over 10 years ago, yikes! – AnthonyWJones Dec 13 '11 at 12:23

1 Answers1

5

It does it in a very similar way. A class that supports foreach has a method that has the DispID of -4 which returns an enumerator object similar to an implementation of IEnumerator.

If you intend to implement this in VB6 then whilst it is possible you will have to be prepared to jump through prohibitively complicated hoops, especially since such insanely complicated stuff is now well past its sell by date. The COM equivalent to IEnumerator is stole.IEnumVARIANT, one characteristic that makes it incompatible with a simple implementation in VB6 is that its Next method uses S_FALSE HResult.

If you really, really want to do this then get this book: Advanced Visual Basic 6 if you can. Warning from a typical VB6 developers point of view the term "Advanced" doesn't really do it justice. "Insanely deep VB6" would be a better description.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • 1
    +1 but isn't it worth mentioning the easy way to implement this in VB6: just use a Collection object? – MarkJ Dec 13 '11 at 17:29
  • @MarkJ: True you could add to your object that represents some collection of things a property that returns a Collection containing a copy of the set of things your object contains. – AnthonyWJones Dec 13 '11 at 17:55
  • @AnthonyWJones, thanks for your answer. Very helpful. Glad you enjoyed the question. Based on what you said I decided to take the easier route. I built a simple Active Record class which is exposed via simple Interface. The interface exposes itself via COM. Example members include: EOF, MoveNext, MoveFirst, Fields etc. – Ian McShane Jan 18 '12 at 08:12