I want to use CallByName to call different functions on an object.
The functions can all have a different number of arguments.
CallByName is defined as:
Function CallByName(Object As Object, ProcName As String, CallType As VbCallType, Args() As Variant)
But when i pass a variant array, an error is generated (Argument not optional)
It works when I pass the arguments one by one, but i need it to work with a variable number of parameters.
The following is a sample to reproduce the problem.
VB Code:
Private Sub Command1_Click() Dim params() As Variant Dim Result As Variant ReDim params(1) params(0) = "Test" params(1) = "test" Result = CallByName(Me, "MyFunction", VbMethod, "Test", "Test") '<-- This will work Result = CallByName(Me, "MyFunction", VbMethod, params) '<-- The produces an error End Sub Public Function MyFunction(ByVal a As String, ByVal b As String) As String MyFunction = a & b End Function




Reply With Quote