Public Function ReplaceArgs(ByVal Text As String, _
ParamArray args() As Variant) As String
However, when I do this, args becomes a 2 dimensional array, with all of
the original arguments in the first "row" of the array. Is there anyway to
prevent this from happening.
Thanks,
Erin
Public Function ReplaceArgs(ByVal Text As String, _
ParamArray args() As Variant) As String
Dim vNewArray As Variant
vNewArray = args
Call MySub(vNewArray)
End Function
Private Sub MySub(SomeArgs As Variant)
Dim i As Integer
For i = 0 To UBound(SomeArgs)
Debug.Print SomeArgs(i)
Next
End Sub
Private Sub Command1_Click()
Call ReplaceArgs("SomeText", "This", "That", "The Other")
End Sub
'=======
--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..
"Erin Stanfill" <erin.stan...@gmail.com> wrote in message
news:op.syjf3ecwjgucr1@chris...
Here is some sample code that passes the contents of a parameter
array into another function for processing (note the use of the
intermediate array). See if this helps you any.
Private Sub Form_Load()
Debug.Print MainFunction(1, 2, 3, 4, 5)
End Sub
Function MainFunction(ParamArray Stuff()) As Long
Dim IntermediateArray() As Variant
IntermediateArray = Stuff
MainFunction = CountThem(IntermediateArray())
End Function
Function CountThem(NormalArrayIn()) As Long
CountThem = UBound(NormalArrayIn) - LBound(NormalArrayIn) + 1
End Function
Rick
But you loose the ByRef attribute of all the elements. About the only way
to pass a parameter array, while preserving all of its attributes is to re-create
the array as needed:
Private Sub Form_Load()
Dim a, b
a = 10
b = 10
Sub1 a, b
Debug.Print a, b ' Prints 1 2
End Sub
Sub Sub1(ParamArray X())
X(0) = 1 ' ByRef assignment
Select Case UBound(X)
Case 0
Sub2 X(0)
Case 1
Sub2 X(0), X(1)
' etc...
End Select
End Sub
Sub Sub2(ParamArray Y())
Y(1) = 2 ' ByRef assignment
End Sub
Ah... true. I knew there had to be a reason that, every time I've considered
using ParamArray, I chose not to <g> There's always one "gotchya" that makes
me decide to use "something else" instead.