Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Passing ParamArray to another function converts it to TWO dimensions.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
baobob@my-deja.com - 31 Jan 2008 04:43 GMT
If I set watch points for Params and SubParams below, I find that
Params has one dimension but SubParams has TWO:

 Function Func(ParamArray Params) as String
   ... = SubFunc(Params)
 End Function

 Function SubFunc(ParamArray SubParams) as String
   ...
 End Function

The following (to me) ludicrous kludge fixes the problem, making
SubParams the nice, obedient 1-dim array equivalent to Params that it
should be:

 Function Func(ParamArray Params)
   ... = SubFunc(Params(0))
 End Function

What in HELL is this? String theory?

***
Kalpesh - 31 Jan 2008 07:00 GMT
Hi,

When you call Func, you would be passing in argument with comma
seperated values.
e.g. Func(1,2,3,4)

ParamArray is intended for variable number of arguments, which will be
treated as array internally (when inside method)
In case of subfunc, you are passing only 1 argument (which is an array
as converted by func)

Looking at the code, you are passing the array entirely to SubFunc.
So, subfunc will create an array & store your array (as you passed it
to Func) - in 0th element

HTH
Kalpesh
Charles Williams - 31 Jan 2008 08:53 GMT
I think this is the recommended method for passing a paramarray argument to
a sub or function

Option Explicit
Function tester(arg1 As Variant, ParamArray arg2() As Variant)
Dim vv As Variant

vv = arg2

tester = test2(vv)

End Function

Function test2(varg As Variant)
 test2 = varg
End Function

regards
Charles
__________________________________________________
Outlines for my Sessions at the Australia Excel Users Group
http://www.decisionmodels.com/OZEUC.htm

> If I set watch points for Params and SubParams below, I find that
> Params has one dimension but SubParams has TWO:
[quoted text clipped - 18 lines]
>
> ***
baobob@my-deja.com - 31 Jan 2008 15:25 GMT
Kalpesh & Charles:

Thanks very much for your replies.

And you make me understand what's going on.

Turns out, I was WRONG in saying that passing single element Params(0)
fixed the problem. Params(0) was reduced to 1 dim all right, but it
has only 1 element.

I'll try your suggestion.

Thanks again.

***
baobob@my-deja.com - 31 Jan 2008 15:35 GMT
Charles:

Your method works: namely, forget about 'ParamArray' in SubFunc, and
just make the arg an array. I hadn't thought of that. Duh.

Thanks again.

***
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.