Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: CallByName Method


Message #1 by "Bhaskar" <b.rai@w...> on Tue, 18 Dec 2001 14:37:03
Bhaskar,
here is an interesting information from the article:
 Use VB6 Now
Learn the major new features of VB6.
by Francesco Balena (http://www.vbhow.to/articles/fb1298/fb1298.asp ):
******************************************
Another welcome addition to VB is the capability to invoke an object's
property or method through its name, using the CallByName function: 

' retrieving the value of a property
res = CallByName(myObject, "LastName", vbGet)
' calling a method with two arguments
CallByName myObject, "EvalExpression", VbMethod, value1, _
   value2
However, this solution leaves much to be desired, because VB still doesn't
offer a method to enumerate the members of an interface. Moreover, although
you can pass an expression as the method's name, you can't use an array in
place of the argument list, which means you still need a Select Case block
to discern among methods that expect a different number of arguments. 
*******************************************************
As you see, it's answer your question, unfortunately negative.
	Eva



-----Original Message-----
From: Bhaskar [mailto:b.rai@w...]
Sent: Tuesday, December 18, 2001 9:37 AM
To: professional vb
Subject: [pro_vb] CallByName Method


Hi All

I would like to use CallByName method of VB to call some of methods.

I found that the syntax is

retval=CallByName(object, procname, calltype,[args()])

I have multiple methods to call and each of them have different number of
arguments and are of different data type.I would like to use a single 
CallByName
function to call each of these methods.

The code looks somewhat like this

Dim v() as variant

for loop...
    ............
    strProcedure="methodA"
    v(0)=1
    v(1)= "Hello"
    retval=CallByName(obj,strProcedure,vbmethod,v)
    ..........
next

But I am geting error Type Mismatch -RunTime error 13  when the CallByName
method is executed.
Is the last argument of CallByName method a variant array ?
If its paramArray , is there any way of coding for this dynamically ?


If not Is there any alternative to CallByName in VB ?

Thanx in advance

Bhaskar

  Return to Index