Li,
Look at the classes in the System.Reflection namespace. Which is what the
CallByName method is built-on.
You can use System.Reflection to get a list of methods for an object, given
this list you can verify that the name exists.
If the name is known at compile time I would recommend using a Delegate as
Jan suggested, if you are reading the name from a source external to your
program, then you will need to use CallByName along with the
System.Reflection namespace to call the method.
Of course reading the name of the function to call from an external source
opens a back door into your program allowing functions that should not be
called to be called!
I do not have a specific example of Reflection to verify the name for you.
Hope this helps
Jay
"Li Pang" <li*****@eu.altria.com> wrote in message
news:0a****************************@phx.gbl...
Hi Armin,
Thanks for your information. To avoid the errors, is that
possible to use some methods to check if the functions
exist before call them?
regards
-----Original Message-----
"Li Pang" <li*****@eu.altria.com> schrieb Hi,
I'd like to know how to call a sub/function bu using a
string containing its name, as an example as follow:
Sub Main()
Dim name As String = "TestMe()"
' need help here
End Sub
Public Sub TestMe()
MsgBox("Hello")
End Sub
Thanks in advance
What happens if the procedure name does not exist? The
application willcrash because the compiler can't find this error.
If you really need it, you can use CallByName (shared
member ofMicrosoft.VisualBasic.Interaction).
--
Armin
.