eval function? how to call dynamic function name 
Author Message
 eval function? how to call dynamic function name

is there an eval function in vb.net
how do i do this

dim vFunction as string
vFunction="evaluateTest"
call vFunction
or
return=vFunction



Tue, 12 Oct 2004 09:12:46 GMT  
 eval function? how to call dynamic function name
Hi,

You can use the CallByName VB methode of the
Microsoft.VisualBasic.Interaction class.

Or you can create your own function

    Public Function MyCallByName(ByVal O As Object, ByVal functionName As
String, ByVal Parameters() As Object) As Object
        Try
            Dim T As Type
            Dim MI As MethodInfo
            Dim ParamTypes(Parameters.Length - 1) As Type
            Dim i As Integer

            For i = 0 To Parameters.Length - 1
                ParamTypes(i) = Parameters(i).GetType
            Next i

            T = O.GetType
            MI = T.GetMethod(functionName, ParamTypes)

            Return MI.Invoke(O, Parameters)

            MI = Nothing
            T = Nothing
        Catch
            Return Nothing
        End Try
    End Function

The first parameter is the object or the module where the function is
implemented.

For exemple, you can use the functions like that :

Dim S As String

S = ""
S = S.Concat("Essai", " Toto")
Debug.WriteLine(S)

S = ""
S = CType(CallByName(S, "Concat", CallType.Method, New Object() {"Essai", "
Toto"}), String)
Debug.WriteLine(S)

S = ""
S = CType(MyCallByName(S, "Concat", New Object() {"Essai", " Toto"}),
String)
Debug.WriteLine(S)



Quote:
> is there an eval function in vb.net
> how do i do this

> dim vFunction as string
> vFunction="evaluateTest"
> call vFunction
> or
> return=vFunction



Tue, 12 Oct 2004 17:09:45 GMT  
 
 [ 2 post ] 

 Relevant Pages 

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

2. execute a variable as a function/sub procedure (like eval function in java(script))

3. Does VBScript has a function similar to JScript function eval

4. Dynamic function calls

5. Executing Function using String Containing Function Name

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

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

8. How to invoke function when function name is in a string

9. Q-Function-name passing to other function

10. Q-Function-name passing to other function

11. functions calling other functions

12. Call Function using Func Name stored in variable

 

 
Powered by phpBB® Forum Software