Execute a String

  • Thread starter Thread starter zurg
  • Start date Start date
Z

zurg

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"?
 
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)
 
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?
 
Instead of Run use:

Microsoft.VisualBasic.Interaction.CallByName(me,strCommand ,CallType.Method)
 
I get an error:

'Me' is not valid within a Module

this method is perfect to any objects, but what about modules?
 
zurg said:
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.
 
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
 
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...
 
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 said:
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.
 
Back
Top