Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

paramarray from one function to a next

Status
Not open for further replies.

christhedonstar

Programmer
Apr 9, 2007
215
GB
Hi,

I'm looking at code which uses the paramarray keyword.

Here is an example

public function FirstFunction(ParamArray args()) as long

debug.print ubound(args)
FirstFunction = SecondFunction(args())

end function

public function SecondFunction(ParamArray argS()) as long

debug.print ubound(args)

end function

I get in the immediate window:
1
0

Any idea why this happens?

Thanks,

Chris
 



Hi,

What are you supplying to the functions as arguments?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
=FirstFunction(B6:B6,B7:C7)

Where B6 = "MyValue1"
B7 = "MyValue2"
C7 = "MyValue3
 
You're getting the Upper bound index.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
christhedonstar,
I think what Skip is getting at is by passing an array to an array argument your getting an array of arrays.

Said another way [tt]argS()[/tt] in [tt]SecondFunction[/tt] contains a 1 dimensional array that contains a 3 dimensional array.

Hopefully the output from this sample helps to clarify.
Code:
Public Function FirstFunction(ParamArray argS()) As Long
  Dim lngOuter As Long
  Debug.Print "FirstFunction"
  For lngOuter = LBound(argS) To UBound(argS)
    Debug.Print "  argS("; CStr(lngOuter); ") = "; argS(lngOuter)
  Next lngOuter
  Debug.Print
  FirstFunction = SecondFunction(argS())
End Function

Public Function SecondFunction(ParamArray argS()) As Long
  Dim varBuffer As Variant
  Dim lngInner As Long, lngOuter As Long
  Debug.Print "SecondFunction"
  For lngOuter = LBound(argS) To UBound(argS)
    varBuffer = argS(lngOuter)
    For lngInner = LBound(varBuffer) To UBound(varBuffer)
      Debug.Print "  argS("; CStr(lngOuter); ","; CStr(lngInner); ") = "; varBuffer(lngInner)
    Next lngInner
  Next lngOuter
End Function

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top