Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Interesting CallByName limitation (VB 6)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Eric Coleman
Gladiator

USA
811 Posts

Posted - May 28 2005 :  11:27:11 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
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
   'Error  
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)?

Almar
Moderator

Netherlands
192 Posts

Posted - Jun 04 2005 :  1:54:12 PM  Show Profile  Visit Almar's Homepage  Send Almar an ICQ Message  Reply with Quote
Tried something ,but no luck either Eric :(

Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jun 04 2005 :  6:17:12 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
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.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.12 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.