Consulting

Results 1 to 8 of 8

Thread: Variants as Array

  1. #1
    VBAX Regular
    Joined
    Feb 2005
    Posts
    9
    Location

    Variants as Array

    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?

  2. #2
    VBAX Contributor Aaron Blood's Avatar
    Joined
    Sep 2004
    Location
    Palm Beach, Florida, USA
    Posts
    130
    Location
    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?

  3. #3
    VBAX Regular
    Joined
    Feb 2005
    Posts
    9
    Location
    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....

  4. #4
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    I was in the panhandle for a couple'a years.
    ~Anne Troy

  5. #5
    VBAX Contributor Aaron Blood's Avatar
    Joined
    Sep 2004
    Location
    Palm Beach, Florida, USA
    Posts
    130
    Location
    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...r_toolbars.zip

  6. #6
    VBAX Regular
    Joined
    Feb 2005
    Posts
    9
    Location
    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.

  7. #7
    VBAX Contributor Aaron Blood's Avatar
    Joined
    Sep 2004
    Location
    Palm Beach, Florida, USA
    Posts
    130
    Location
    You might just be able to use something like...

    For i = 0 to UBound(ReturnVal)

  8. #8
    VBAX Regular
    Joined
    Feb 2005
    Posts
    9
    Location
    Awesome that is what I needed! Thanks for your patience!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •