Question : Collection declartaion in VBA

I have a class module called 'DespatchNote'
I have a second class called 'Consigment'
Consignment has a collection called DespatchNotes.
I can succesfully handle the collection in the Consignment class (Add, Remove,Count) but how can I declare a property in Consignment that would expose the collection to VBA normal module code?
I'd like to write code similar to this

dim c as New Consignment
c.ConNumber='A123'
c.GetDespatchNotes
for each DespatchNote in c.DespatchNotes
  debug.print DespatchNote.Name
next DespatchNote

Thanks for your help
Andy

Answer : Collection declartaion in VBA

In addition to the links provided by Gary:

I'm not sure you can do what you're looking for directly in the Class, but you could expose the Collection through an interface:

Public Property Get myCollection As Collection
  myCollection = YourCollectionObject
End Property

Your code could then use it like this:

Dim vColl As Collection

Set vColl = YourClass.myCollection

You could then loop through the vColl object.

I personally don't use collections, and prefer instead to work with arrays in my Classes. Even at that, I still have the same issue - I can't do a For Each loop through any interface of my class.
Random Solutions  
 
programming4us programming4us