How to invoke function when function name is in a string 
Author Message
 How to invoke function when function name is in a string

Hi,

How can I invoke a function or a sub when the name of the function/sub
I want to invoke is contained in a string variable?

 I think I need something like the VB equivalent of the Access Eval()
function, but cannot find anything similar in VB.

Thanks

george ton



Mon, 22 Mar 1999 03:00:00 GMT  
 How to invoke function when function name is in a string



Quote:
> Hi,

> How can I invoke a function or a sub when the name of the function/sub
> I want to invoke is contained in a string variable?

>  I think I need something like the VB equivalent of the Access Eval()
> function, but cannot find anything similar in VB.

> Thanks

> george ton

I don't have an answer to this, but if you find one please post and or cc
me.

I have programmed AutoLisp for years and have made extensive use of the
(read(eval "Text String")) ability.
I mean really, all you want to do is strip off the f*** quotes.

--



Tue, 23 Mar 1999 03:00:00 GMT  
 How to invoke function when function name is in a string

: How can I invoke a function or a sub when the name of the function/sub
: I want to invoke is contained in a string variable?

:  I think I need something like the VB equivalent of the Access Eval()
: function, but cannot find anything similar in VB.

VB probably doesn't have a feature like that, so you will probably need
to write CODE to do it.  Create a procedure that you pass your string to,
and use a "CASE" structure or something to handle it.

It seems there should be a way to call a DLL if you've got the name of the
function, but I don't know how to do it -- or whether VB provides a way.



Wed, 24 Mar 1999 03:00:00 GMT  
 How to invoke function when function name is in a string

This is a silly solution, of no *real* value at all,

Let us assume we have two functions we wish to call using the contents of a
string variable. Call the functions hello and goodbye.

1)      Create 1 class for each function you want to call. In each class create
a single function, call it method for example.

        So we have two classes called "hello" and "goodbye" and they both have 1
method called "method". It is invoked by using

        dim a as new hello

        call a.method

Wow!! big deal.........well..

2)      Make each class creatable and public using the class properties page.

3)      Set the Project name to be the same as the executable name.

4)      Write a function like this below

Function polymorphicCall(sName As String) As Variant
    Dim s As String
    Dim oBj As Object
    s = App.EXEName & "." & sName
    Set oBj = CreateObject(s)

    polymorphicCall = oBj.method
End Function

5) You should be able to execute functions passing the function name as a
parameter to polymorphicCall.

This scores:

        0 for speed
        5 for trickness
        10 for the "Why?" quotient

Regards stu



Quote:

> : How can I invoke a function or a sub when the name of the function/sub
> : I want to invoke is contained in a string variable?

> :  I think I need something like the VB equivalent of the Access Eval()
> : function, but cannot find anything similar in VB.

> VB probably doesn't have a feature like that, so you will probably need
> to write CODE to do it.  Create a procedure that you pass your string to,
> and use a "CASE" structure or something to handle it.

> It seems there should be a way to call a DLL if you've got the name of
the
> function, but I don't know how to do it -- or whether VB provides a way.



Tue, 30 Mar 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Executing Function using String Containing Function Name

2. how can I use function pointer to invoke a function in Visual Basic

3. eval function? how to call dynamic function name

4. Getting the function's name during runtime while running in the scope of the function

5. Returning sub or function name within a specific sub or function

6. Q-Function-name passing to other function

7. Get the name of a function that calls another function

8. Q-Function-name passing to other function

9. Run a function whose name is stored in a string

10. Assigning function name to a string value

11. Passing a function name as a string

12. How can a program take a string as the name of a function

 

 
Powered by phpBB® Forum Software