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)

Note: You must be registered in order to post a reply.

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List Spell Checker
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert an File
Check here to include your profile signature.
Check here to subscribe to this topic.
    

T O P I C    R E V I E W
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
   '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)?
2   L A T E S T    R E P L I E S    (Newest First)
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 © Go To Top Of Page
This page was generated in 0.19 seconds. Snitz Forums 2000

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