Call a function with a variable name 
Author Message
 Call a function with a variable name

Is there anyway to call a function using a variable name for the function
name?  I have some function names stored in a table that I would like to be
able to execute.  The functions are defined as standard public functions.

If this could work, I could do what I need to.

Dim strFunctionName As String

If Status = "A" Then
     strFunctionName = "Test1"
Else
     strFunctionName = "Test2"
End If

Call strFunctionName

Thanks
--
Jeff Crane
DataVision Corporation



Sun, 10 Sep 2000 03:00:00 GMT  
 Call a function with a variable name

Hi,

You have to use Eval function.  Try something like this
Function fEval(status As String)
Dim strFunctionName As String
Dim x
    If status = "A" Then
        strFunctionName = "TestThat()"
    Else
        strFunctionName = "TestThis()"
    End If

    fEval = Eval(strFunctionName)
End Function
Function TestThis()
    Debug.Print "testthis"
End Function
Function testThat()
    Debug.Print "Test That"
End Function

HTH
--
Please limit questions to newsgroups only...
Just my $.001
Dev Ashish
---------------
The Access Web ( http://home.att.net/~dashish )
---------------

Quote:

>Is there anyway to call a function using a variable name for the function
>name?  I have some function names stored in a table that I would like to be
>able to execute.  The functions are defined as standard public functions.

>If this could work, I could do what I need to.

>Dim strFunctionName As String

>If Status = "A" Then
>     strFunctionName = "Test1"
>Else
>     strFunctionName = "Test2"
>End If

>Call strFunctionName

>Thanks
>--
>Jeff Crane
>DataVision Corporation




Sun, 10 Sep 2000 03:00:00 GMT  
 Call a function with a variable name

Yes you can!!!

Use the eval function:

sub UseEval()

    dim strFunctionName as String
    dim intResult as Integer

    strFunctionName="DoubleIt(4)"

    ' intResult will contain the result of funtion MyFunction which is 8
     intResult = eval(strFunctionName)

end sub

function DoubleIt(intNumber as integer) as integer
     DoubleIt=intNumber*2
end function

Daniel Kuhlmann

KONO Automatiseringsdiensten
Spijkerstraat 319
6828 DK  Arnhem
The Netherlands
Tel: (+31)(0) 26 44 58 214

Home page: www.tip.nl/users/daniel.kuhlmann/

Quote:

>Is there anyway to call a function using a variable name for the function
>name?  I have some function names stored in a table that I would like to be
>able to execute.  The functions are defined as standard public functions.

>If this could work, I could do what I need to.

>Dim strFunctionName As String

>If Status = "A" Then
>     strFunctionName = "Test1"
>Else
>     strFunctionName = "Test2"
>End If

>Call strFunctionName

>Thanks
>--
>Jeff Crane
>DataVision Corporation




Wed, 13 Sep 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Calling function or sub with variable array or string names

2. Help with using names and variables in a function call

3. Call Function using Func Name stored in variable

4. Calling a sub procedure whose name is in a variable: call me.ProcToRun

5. how do i call a function by using the function name as a string of characters

6. Procedure call with name as a variable?

7. calling sub by variable name

8. Calling a procedure using a variable name

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

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


 
Powered by phpBB® Forum Software © phpBB Group