I'm posting this to see if anyone else has had this issue, especially for scripting engines. The help file for CallByName is wrong, the last paramter is not an Array of type Variant. The CallByName's last parameter is a ParamArray delcaration.
The problem I've run into is that I can't dynamically call "CallByValue." What I mean by that is I can't create a wrapper function for it.
CallByName is generally called like so...
CallByName MyObject, "TestMethod", vbMethod, A, B, C, D, E, F, G
Where the parameters A, B, C, etc. are all optional.
The limitation that I've run into is that the following CAN NOT work...
Public Sub MySub(objObject as Object, strName as String, ParamArray p())
CallByName objObject, strName, [... ??? ...]
End Sub
If no parameters other than the required "objObject" and "strName" are passed to MySub, then the upper bound of "p" will be -1. Calling the sub like so, MySub o, "tmp", A, B, C, D would yield the array p to be from 0 to 3, where p(0) = A, p(1) = B, etc.
The only option that I can think of is to have a giant select case statement and hope that I don't ever go over some predefined limit of paramters for a function.
Public Sub MySub(objObject as Object, strName as String, ParamArray p())
Select Case Ubound(p)
Case -1
CallByName objObject, strName
Case 0
CallByName objObject, strName, p(0)
Case 1
CallByName objObject, strName, p(0), p(1)
Case 2
CallByName objObject, strName, p(0), p(1), p(2)
Case 3
CallByName objObject, strName, p(0), p(1), p(2), p(3)
Case 4
CallByName objObject, strName, p(0), p(1), p(2), p(3), p(4)
Case Else
End Sub
As you can tell, this is very limiting, and because it can't handle arbitrary numbers of paramters, it sucks.
Other than the large Select Case solution, does anyone have any ideas on how to pass an unknown number of parameters at runtime to a CallByName function (or any function for that matter)?