-
Execute method from string
Is there a way (I'm guessing thru IUnknown or IDispatch) to execute a method
based on the contents of a string variable? For example, I pass a string
to a sub or function that contains the class to call (DLL.clsExample), and
another string that contains the method I want to call (GetInformation).
I know I can instantiate the object by doing a CreateObject on the class
string, but how can I call the method that I passed in the other string variable?
Thanks for any help.
-
Re: Execute method from string
"jk1121" <jk1121@aol.com> wrote in message news:3b66e44b$1@news.devx.com...
>
> Is there a way (I'm guessing thru IUnknown or IDispatch) to execute a
method
> based on the contents of a string variable? For example, I pass a string
> to a sub or function that contains the class to call (DLL.clsExample), and
> another string that contains the method I want to call (GetInformation).
> I know I can instantiate the object by doing a CreateObject on the class
> string, but how can I call the method that I passed in the other string
variable?
> Thanks for any help.
In VB6, you can use CallByName.
Eg,
Dim obj As Object
Dim varResult As Variant
Set obj = CreateObject("MyProject.MyClass")
CallByName obj, "MyProcedure", vbMethod, Arg1, Arg2
varResult = CallByName(obj, "MyFunction", vbMethod, Arg1)
--
Colin McGuigan
-
Re: Execute method from string
Thanks Colin, works perfect!
I can't believe I've been doing this for 3 yrs and never heard of CallByName...
"Colin McGuigan" <cmcguigan@imany.com> wrote:
>
>"jk1121" <jk1121@aol.com> wrote in message news:3b66e44b$1@news.devx.com...
>>
>> Is there a way (I'm guessing thru IUnknown or IDispatch) to execute a
>method
>> based on the contents of a string variable? For example, I pass a string
>> to a sub or function that contains the class to call (DLL.clsExample),
and
>> another string that contains the method I want to call (GetInformation).
>> I know I can instantiate the object by doing a CreateObject on the class
>> string, but how can I call the method that I passed in the other string
>variable?
>> Thanks for any help.
>
>In VB6, you can use CallByName.
>
>Eg,
>
>Dim obj As Object
>Dim varResult As Variant
>
>Set obj = CreateObject("MyProject.MyClass")
>CallByName obj, "MyProcedure", vbMethod, Arg1, Arg2
>varResult = CallByName(obj, "MyFunction", vbMethod, Arg1)
>
>--
>Colin McGuigan
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks