+ Reply to Thread
Results 1 to 2 of 2

Passing Object Array to a Subroutine

  1. #1
    Registered User
    Join Date
    04-21-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Passing Object Array to a Subroutine

    Second question of the day.

    Suppose I want to have an array of objects as an input parameter to a subroutine. What is the syntax for this?

    Suppose, "A" is an array of "Foo" object, where "Foo" is a user-defined class. How do I pass "A" to another subroutine or function? Here are some failed syntax examples:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

    I've tried passing it as a variant, but I get the error "ByRef argument type mismatch".

    Any help appreciated.

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Passing Object Array to a Subroutine

    Hi,

    The signature of your first code snippet is correct. Arrays must be passed ByRef in VBA so, if it expects to be passed an array of Foo, then you must pass in an array of Foo and not a Variant.

    A simple example:
    Please Login or Register  to view this content.
    If you show us how you are trying to pass the argument into the procedure then we can be more specific?
    Last edited by Colin Legg; 04-21-2011 at 03:12 PM.
    Hope that helps,

    Colin

    RAD Excel Blog

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1