Note: You must be registered in order to post a reply.
|
Eric Coleman |
Posted - May 28 2005 : 11:27:11 PM 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)? |
Eric Coleman |
Posted - Jun 04 2005 : 6:17:12 PM I ended up using Select Case for up to 10 paramters. If any function requires more then 10 parameters, then the function's paramters will be passed ByVal instead of ByRef. The EventParamters object is really strange, no matter what I do I can't pass a value by reference. |
Almar |
Posted - Jun 04 2005 : 1:54:12 PM Tried something ,but no luck either Eric :( |
|
|
VBGamer |
© |
|
|
|
|