
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