View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Brian Brian is offline
external usenet poster
 
Posts: 683
Default Passing arrays through procedures

Thanks Chip, it works like a charm.
--
Brian


"Chip Pearson" wrote:

The problem arises because your Sort function declares its input
parameter as an array of Variants:

Sub Sort(arr() as Variant)

This means that you must pass to it something that the compiler knows
is an array. However, in your GetMonths procedure, you get arrDate as
a single Variant, not an array of Variants. While a Variant can
contain an array, it does not necessarily contain an array as far as
the compiler is concerned. Thus, the compiler complains that it needs
an array. You can change the declaration of your Sort procedure so
that it expects a single Variant (which contains an array) rather than
an array of Variants.

Change
Sub Sort(arr() as Variant)

To
Sub Sort(arr as Variant)


Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




On Mon, 18 Jan 2010 11:14:01 -0800, Brian
wrote:

All,

I'm getting a compile error: Type mismatch: array or user-defined type
expected on the "Call Sort(arrDate)" line. What should I be looking for to
troubleshoot this? Below are the lines of code that deal with arrDate.

Sub Button17_Click()
ReDim arrDate(0)
Call GetMonths(arrDate,arrSite)
Call SiteSelected(arrDate,arrSite)
End Sub

Sub GetMonths(arrDate, arrSite as Variant)
'Here is where I build arrDate and send to Sort to get them in order
Call Sort(arrDate)
End Sub

Sub Sort(arr() as Variant)
'Sort array in order
End Sub

Sub SiteSelected(arrDate,arrSite as Variant)
'Here arrDate is actually used
End Sub

I know my arrDate array gets built properly because it appears correctly in
the SiteSelected Procedure when I skip the Sort Procedure. Clearly I don't
know how to pass arrays through procedures effectively so any help with that
would be appreciated also.

.