PDA

View Full Version : [SOLVED:] Variants as Array



kscott
03-07-2005, 10:33 AM
I have an excel spreadsheet which recieves an array of custom objects. I've tried to do something like


For Each item In returnVal
msgbox item.someField
next item

where item is declared as an object of the custom type

I get an error message "object required".

How can I get this variant object to act like an array so that I can iterate through it and find the data in all the objects?

Aaron Blood
03-07-2005, 01:44 PM
I think you might need to put the objects in a collection if you want to step thru them with a For/Each.

So wherebouts in Florida?

kscott
03-07-2005, 01:48 PM
Aaron,
thanks for the reply. Please forgive my newbieness, I'm actually a Java guy. How exactly do I put the variant objects into a collection?

I'm in the panhandle....

Anne Troy
03-07-2005, 02:04 PM
I was in the panhandle for a couple'a years. :)

Aaron Blood
03-08-2005, 07:06 AM
You're description of the ReturnVal set of objects (if that's what it is) is a bit vague. I have an example of how to add user toolbars to a collection. Shows how to add objects to a collection. But I can't really tell if it will work for you situation or not.

http://www.xl-logic.com/xl_files/vba/save_user_toolbars.zip

kscott
03-08-2005, 07:12 AM
Sorry for the vagueness. What I have is a web service method that returns a Variant object. This variant object is really an array of custom types. What I want to figure out is to figure out how iterate through this objects and get information from them.

Aaron Blood
03-08-2005, 07:32 AM
You might just be able to use something like...


For i = 0 to UBound(ReturnVal)

kscott
03-08-2005, 07:39 AM
Awesome that is what I needed! Thanks for your patience!