executing functions from a string at run time

So I made a module with a list of functions that make my life easier. I am expirimenting with this sort of thing, and I am trying to make a little command line sort of thing to be used at run time. My question is:

Is there a way to execute internal functions like the ones I made by typing them into a text box at run time (and clicking a button or whatever)? I'm looking for something like:

Execute(command.text)

Thanks!

[453 byte] By [subsonic] at [2007-12-21]
# 1

There's the scripting object for VBScripting, or there is the VBCodeProvider Class (There's a C# one, too) which allows you to compile and Execute VB code.

However, this may not be exactly what you are looking for: what exactly are these 'functions' that you mention (What sort of things do they do)?

SJWhiteley at 2007-9-10 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2

you can also use system.reflection to pull method names from an assemply module and test your string against the name of the method to be invoked...

Public Function Invoke(ByVal obj As Object, ByVal parameters() As Object) As Object

Member of: System.Reflection.MethodBase

Summary:

Invokes the method or constructor represented by the current instance, using the specified parameters.

DMan1 at 2007-9-10 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3

well, I'm not sure if that's what I want or not, I'll look into it more in a sec...

And for the functions... for example: (it's a stupid one)

Function show_message(ByVal text As String)

MsgBox(text)

End Function

I want the to be able to type show_message("Hello") into a text box and it come up with a message box saying hello.

subsonic at 2007-9-10 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 4
I'm sorry, but I don't understand fully. I get what it means, but I don't know how to do it!
subsonic at 2007-9-10 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 5

First of all what you are trying to accomplish is not an easy task...you need to have a thourough understanding of the reflection namespace...You will also have to do some serious parsing of the text from the textbox...especially if parameters and functions will be included in the same text box....you could always use select case statements after parsing to run the correct function or you can even fill a combo box with the string names of your funtion and then execute accrding to what the user selects....

In either case we are at a point in which you need to make a choice of which road you would like to travel and then start down that road. Once you get stumped...come back and post the code you are stumped with and the problem you are having. You will get much better answers to your question that way!

DMan1 at 2007-9-10 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 6

You may want to look at the CallByName function, it hides a lot of the reflection details from you:

http://msdn2.microsoft.com/en-us/chsc1tx6.aspx

Hope that helps,

Jonathan Aneja

The VB Team

JonathanAneja-MSFT at 2007-9-10 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 7
Yes, I'd start with the CallByName functionality before delving into the others mentioned. It may do precisely what you need.
SJWhiteley at 2007-9-10 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...