Traversing VBA.Collection

  • Thread starter Thread starter Josh
  • Start date Start date
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
 
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.
 
Back
Top