jwcolby
jwcolby at colbyconsulting.com
Wed Mar 12 10:49:27 CDT 2008
Drew,
LOL.
>Ya learn something new everyday.
Would you speak into the microphone please...
The "solution" did the trick, but at the expense of eliminating the ability
to pass in multiple arguments to SecondParamfunction. It is the keyword
ParamArray that allows the passing in of multiple arguments. It is often
useful to have two functions, BOTH of which have param arrays, and be able
to call either one directly, but also call one from the other. It is the
"call one from the other" that is not possible if both have paramarrays.
ParamArrays are indeed a neat trick and one I use all of the time. What
would be REALLY cool would be to be able to pass into TWO paramarrays but
that is syntactically impossible - there is no way to denote where
parameters aimed at one array ends and where the parameters aimed at the
next array begins. The language could be expanded to allow a semicolon to
denote the end of one list and the beginning of the next but that doesn't
currently exist.
John W. Colby
Colby Consulting
www.ColbyConsulting.com
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Drew Wutka
Sent: Wednesday, March 12, 2008 11:14 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Feeding an paramarray to a paramarray
Ya learn something new everyday. Never even knew about the ParamArray
option. Pretty slick. Anyhow, I whipped out my trusty 'solve all my
problems' tool, otherwise known as Google, and on the second page of hits
for ParamArray, I found this:
http://support.microsoft.com/kb/157351
Sure enough, changing this:
Function TestParamArray(strSomething As String, ParamArray tmpParams() As
Variant) Dim varMember For Each varMember In tmpParams
Debug.Print strSomething & " " & varMember
SecondParamFunction tmpParams
Next
End Function
Function SecondParamFunction(ParamArray tmpParams() As Variant) Dim
varMember For Each varMember In tmpParams
Debug.Print varMember
Next
End Function
To this:
Function TestParamArray(strSomething As String, ParamArray tmpParams() As
Variant) Dim varMember For Each varMember In tmpParams
Debug.Print strSomething & " " & varMember
SecondParamFunction tmpParams
Next
End Function
Function SecondParamFunction(ByVal tmpParams As Variant) Dim varMember For
Each varMember In tmpParams
Debug.Print varMember
Next
End Function
Did the trick!
Drew
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Wednesday, March 12, 2008 5:23 AM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] Feeding an paramarray to a paramarray
Paramarrays are very useful.
function ListGrpMembers(ParamArray GrpMembers() as variant) dim varGrpMember
for each varGrpMember in GrpMembers
debug.print varGrpMember
next varGrpMember
end function
ListGrpMembers "John", "Mary", "Robbie", "Allie"
Paramarrays allow you to feed a variable number of values into a function,
and then easily manipulate the array that they are placed in using a for
each iterator.
The problem lies if you then need to feed that array off to another
function.
function LogGrpMembers(Paramarray GrpMembers() as variant) end function
Using a function as shown above doesn't work. If you pass the
GrpMembers()
array assembled in ListGrpMembers into LogGrpMembers you get a runtime
error.
I have "solved" this problem by unpacking the array into a collection and
passing the collection into the next function.
function LogGrpMembers( GrpMembers as collection) end function
function ListGrpMembers(ParamArray GrpMembers() as variant) dim varGrpMember
dim colGrpMembers as collection
set col
for each varGrpMember in GrpMembers
colGrpMembers.Add varGrpMember
next varGrpMember
LogGrpMembers colGrpMembers
end function
While that works, it is cumbersome and there are times where you would
really like the second function to be a ParamArray as well, perhaps so that
it can be called directly if required.
Am I missing something? Is there a syntax for passing a paramarray into
another paramarray?
John W. Colby
Colby Consulting
www.ColbyConsulting.com
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com The information contained in this
transmission is intended only for the person or entity to which it is
addressed and may contain II-VI Proprietary and/or II-VI Business Sensitive
material. If you are not the intended recipient, please contact the sender
immediately and destroy the material in its entirety, whether electronic or
hard copy. You are notified that any review, retransmission, copying,
disclosure, dissemination, or other use of, or taking of any action in
reliance upon this information by persons or entities other than the
intended recipient is prohibited.
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com