By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

Execute a String

P: n/a
Hi!

Is there a way to execute a string?
That means:
1. My app shows dialog box where I write "StartCounting"
2. My program run StartCounting sub
Is there any other way then just using "case"?
Nov 20 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Is StartCounting a method in a class of yours?

if so: something like...

imports System.Reflection
....
dim myType = myObject.GetType()
dim myMethod as MethodInfo = myType.GetMethod("StartCounting")
dim result as Object = myMethod.Invoke(myObject, new Object(){
....parameters...} or Nothing)

"zurg" <zu*****@wp.pl> wrote in message
news:Ol**************@TK2MSFTNGP11.phx.gbl...
Hi!

Is there a way to execute a string?
That means:
1. My app shows dialog box where I write "StartCounting"
2. My program run StartCounting sub
Is there any other way then just using "case"?

Nov 20 '05 #2

P: n/a

Take a look at this
http://www.dotnet247.com/247referenc.../18/90485.aspx


"zurg" <zu*****@wp.pl> schrieb im Newsbeitrag
news:Ol**************@TK2MSFTNGP11.phx.gbl...
Hi!

Is there a way to execute a string?
That means:
1. My app shows dialog box where I write "StartCounting"
2. My program run StartCounting sub
Is there any other way then just using "case"?

Nov 20 '05 #3

P: n/a
* "zurg" <zu*****@wp.pl> scripsit:
Is there a way to execute a string?
That means:
1. My app shows dialog box where I write "StartCounting"
2. My program run StartCounting sub
Is there any other way then just using "case"?


Samples:

<http://www.codeproject.com/useritems/evaluator.asp>
<http://www.codeproject.com/csharp/livecodedotnet.asp>

If you have a DevX account:

<http://www.devx.com/codemag/Article/10352/0/page/1>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

P: n/a
Both of you gave me a helpful answear - thank you!

But I'd like it also to work like this:

Module Module1
Sub Main
Dim strCommand As String

strCommand = "Hello"
Run(strCommand)'or sth like this
End Sub

Sub Hello
Msgbox("Hello")
End Sub
End Module
and it should show "Hello" messagebox...
How to do so?
Nov 20 '05 #5

P: n/a
Instead of Run use:

Microsoft.VisualBasic.Interaction.CallByName(me,st rCommand ,CallType.Method)

"zurg" <zu*****@wp.pl> schrieb im Newsbeitrag
news:O6**************@TK2MSFTNGP10.phx.gbl...
Both of you gave me a helpful answear - thank you!

But I'd like it also to work like this:

Module Module1
Sub Main
Dim strCommand As String

strCommand = "Hello"
Run(strCommand)'or sth like this
End Sub

Sub Hello
Msgbox("Hello")
End Sub
End Module
and it should show "Hello" messagebox...
How to do so?

Nov 20 '05 #6

P: n/a
I get an error:

'Me' is not valid within a Module

this method is perfect to any objects, but what about modules?
Nov 20 '05 #7

P: n/a
"zurg" <zu*****@wp.pl> schrieb
Both of you gave me a helpful answear - thank you!

But I'd like it also to work like this:

Module Module1
Sub Main
Dim strCommand As String

strCommand = "Hello"
Run(strCommand)'or sth like this
End Sub

Sub Hello
Msgbox("Hello")
End Sub
End Module
and it should show "Hello" messagebox...
How to do so?


Where do you get the strings from? Which programming language is used for
these commands? Writing commands is actually a programmer's job. Commands
are parts of projects, and projects are compiled using the compiler, then
executed.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #8

P: n/a

Never used Moduls...... It's very old fashioned to use Moduls.....

Simply create a Class an call it from your Modul if you have a
Console-Application.
The put every thing ito the Class instead of the Moduls Shit.

Like this

Module Module1
Sub Main
dim xy as new MyClass
xy.run("bla")
End Sub
End Module

Class MyClass

Sub Run(bla)

End sub
Sub Hello
Msgbox("Hello")
End Sub

End Class

"zurg" <zu*****@wp.pl> schrieb im Newsbeitrag
news:e0**************@TK2MSFTNGP09.phx.gbl...
I get an error:

'Me' is not valid within a Module

this method is perfect to any objects, but what about modules?

Nov 20 '05 #9

P: n/a
That's of course true...

but I'd like to write quite huge application that can be completly
configurated by the config file.
When I say "completly" I mean that I want as well change some information
inside the app as which funcion should be run...
Unluckly I'm still learning the construcion of the configuration file and I
only now how to read from there only strings...
that's why I'm looking for a way to treat a string like a command to run and
the "case" construction isn't the best for me...
Mayby there's another way to do so using the configuration file... I'm still
working on it...

Hope I made myself clear...
Uzytkownik "Armin Zingler" <az*******@freenet.de> napisal w wiadomosci
news:OL**************@TK2MSFTNGP09.phx.gbl...
"zurg" <zu*****@wp.pl> schrieb
Both of you gave me a helpful answear - thank you!

But I'd like it also to work like this:

Module Module1
Sub Main
Dim strCommand As String

strCommand = "Hello"
Run(strCommand)'or sth like this
End Sub

Sub Hello
Msgbox("Hello")
End Sub
End Module
and it should show "Hello" messagebox...
How to do so?


Where do you get the strings from? Which programming language is used for
these commands? Writing commands is actually a programmer's job. Commands
are parts of projects, and projects are compiled using the compiler, then
executed.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #10

P: n/a
try this
public module modTest
public sub start()
dim t as Type = GetType(modTest)
dim mi as MethodInfo = t.GetMethod("stringStuff")
mi.Invoke(nothing, nothing)
end sub

public sub stringStuff()
...
end sub

end module
"zurg" <zu*****@wp.pl> wrote in message
news:e0**************@TK2MSFTNGP09.phx.gbl...
I get an error:

'Me' is not valid within a Module

this method is perfect to any objects, but what about modules?

Nov 20 '05 #11

P: n/a
Works perfect!!!!
That's the thing I was looking for...

Thank you
Nov 20 '05 #12

P: n/a
KS
The other method did work too !

KS, Denmark

"zurg" <zu*****@wp.pl> skrev i en meddelelse
news:uB**************@TK2MSFTNGP09.phx.gbl...
Works perfect!!!!
That's the thing I was looking for...

Thank you

Nov 20 '05 #13

P: n/a
"zurg" <zu*****@wp.pl> schrieb
That's of course true...

but I'd like to write quite huge application that can be completly
configurated by the config file.
When I say "completly" I mean that I want as well change some
information inside the app as which funcion should be run...
Unluckly I'm still learning the construcion of the configuration file
and I only now how to read from there only strings...
that's why I'm looking for a way to treat a string like a command to
run and the "case" construction isn't the best for me...
Mayby there's another way to do so using the configuration file...
I'm still working on it...

Hope I made myself clear...


Yep. Depending on your application's structure, you own interpreter - the
simplest would be a Select Case - might be a solution.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.