Calling method which name is in a string 
Author Message
 Calling method which name is in a string

Hello,

Object: Calling a method which name is in a string

I would like to be able to run a program like this one.

dim obj as object
dim method as string
obj= createobject("Project.Class")
method = "my method" 'depend on several params ....
call obj.?????????????

I do not want use a select case.
Is it possible to call with indirection ?

Thanks for sharing.



Sat, 23 Dec 2000 03:00:00 GMT  
 Calling method which name is in a string

Quote:

> Hello,

> Object: Calling a method which name is in a string

> I would like to be able to run a program like this one.

> dim obj as object
> dim method as string
> obj= createobject("Project.Class")
> method = "my method" 'depend on several params ....
> call obj.?????????????

> I do not want use a select case.
> Is it possible to call with indirection ?

Why not use select case, it would make things a lot
easier.

The only way I have figured out (using VB4/16) is
to wrap each function in a class by itself.  Each
class would have an Execute method that does the
work:

dim obj as object
dim method as string

Method = "Project1.Method1"  'the needed routine
obj= createobject(Method)
call obj.excute

There may be several methods in Project1...

Method = "Project1.Method2"
Method = "Project1.Method3"
Method = "Project1.Method4"

All are classes in Project1 that can be called using
a string variable in the create process.

I think I read that VB6 is going to address this problem.

Good luck!
LFS



Sun, 24 Dec 2000 03:00:00 GMT  
 Calling method which name is in a string
The *best* way to do this is with OLE.  This feature is included in all COM
objects via the IDispatch interface.  You can access this from VB using
TLBINF32.DLL.  Add this DLL to your project->references and use the Invoke
methods.  No hacky Select statements needed.
Quote:


>> Hello,

>> Object: Calling a method which name is in a string

>> I would like to be able to run a program like this one.

>> dim obj as object
>> dim method as string
>> obj= createobject("Project.Class")
>> method = "my method" 'depend on several params ....
>> call obj.?????????????

>> I do not want use a select case.
>> Is it possible to call with indirection ?

>Why not use select case, it would make things a lot
>easier.

>The only way I have figured out (using VB4/16) is
>to wrap each function in a class by itself.  Each
>class would have an Execute method that does the
>work:

>dim obj as object
>dim method as string

>Method = "Project1.Method1"  'the needed routine
>obj= createobject(Method)
>call obj.excute

>There may be several methods in Project1...

>Method = "Project1.Method2"
>Method = "Project1.Method3"
>Method = "Project1.Method4"

>All are classes in Project1 that can be called using
>a string variable in the create process.

>I think I read that VB6 is going to address this problem.

>Good luck!
>LFS



Sun, 24 Dec 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Using string to specify method to call on object

2. OLE automation - calling method function with string par by reference

3. Calling Class Method / Property with String Variable

4. How to call a method which is in a string

5. How to get the login Name of the Remote machine, I am having the host name

6. calling a contol on a form using a string for the form name

7. Call Let/Get Prop using string variable for name

8. Call Let/Get Prop using string variable for name

9. Call a proc using a string variable for the proc name

10. How to call Form1 from Form2, using string wich is name of the form (Form1)

11. Calling a DLL when you've got the name of it as a string

12. Module name and method name of caller?

 

 
Powered by phpBB® Forum Software