Byron Hopp wrote:
Is this possible in Vb.Net?
Dim strFuncName as String
Dim strFuncParm as String
strFuncName = "MyFunc(strFunc Parm)"
strFuncParm = "Hello World"
Can I call a function which when I pass strFuncName to it, it will
execute the function MyFunc()?
Function MyFunc(strFuncP arm as String)
msgbox strParm
End Function
Like the magic 'Eval()' function in BASICs of times long past? The
short answer is "no" - because at run-time you're not running Basic
code, you're running IL, and something that understands VB (eg a VB
compiler) is far far away.
The slightly longer answer is "yes, if you cheat". VB*Script* has such
a function (Eval()) - so find a Script host in your runtime environment
and persuade it to do what you want...?
Another longer answer is "yes, if you're prepared to work at it". With
the powerful and arcane wizardry known as Reflection, you have runtime
access to all the bits and pieces that make up your program. So find a
procedures called "MyFunc", look at its list of arguments, prepare
those arguments, and Invoke() and you're there.
Finally, I think I saw some code once where IL was dynamically
generated and executed at run time, all from managed code. Can't
remember where or how now, but it's a thought...
--
Larry Lard
Replies to group please