Traversing VBA.Collection

J

Josh

Hi,

I am using an OCX from VB6 that has a routine that outputs a collection.

If "Params" is defined as a collection in VB6,
The following statements (in the VB6 debug window) works:
?Params.Item(8).Value
VB outputs: &HFFFFFF (or whatever)

If am writing C# and I use the OCX that returns this collection,
I use the following definitions:
VBA.Collection commandParams;
commandParams = CommGenX1.getParamCollection();

How can I imitate the command ?Params.Item(8).Value ?
Or at least traverse the collection and print out the values.
I think some are numbers and some are strings...


Many thanks,

Josh
 
N

Nicholas Paldino [.NET/C# MVP]

Josh,

To traverse the collection, you could use a foreach (I believe that
because the collection implements IEnumVariant, this is supported).
However, you can also call the Item function. If you import the VB runtime
library for the Collection definition, then you have to pass the index as a
ref, like so:

// The index.
object pobjIndex = 1;

// Get the item.
object pobjItem = pobjCollection.Item(ref pobjIndex);

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top