Using a string to script a line in my app
Alright basically what I want to be able to do is control my application with a text file converted as a string or just plain from file.
Here's what I have:
Code:
Dim MyStrCmd As String MyStrCmd = My.Computer.FileSystem.ReadAllText("C:\MyApp\Command.txt")
What I want is to be able to is use the string to run a command in my program. I simply what to do a Me.Close() to start (thats all the file contains currently)
How am I able to simply just have my application read the string and execute it on say a the click of a button.
I need something similar to this, just something real simple if possible but I'll try anything you guys can think of.
Code:
Me.BackgroundImage = System.Drawing.Image.FromFile(My.Computer.FileSystem.ReadAllText("C:\MyApp\Resource1.REZ")) 'This works!
So something like
Code:
Run Command = My.Computer.FileSystem.ReadAllText("C:\text.txt") 'What I want
I tried using
Code:
Dim MemStream As New IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes(MyStrCmd))
as well but I don't know how to use it, the page I got this from didn't fully explain but it seemed like ti was talking about what i was looking for.
Re: Using a string to script a line in my app
I've also tried
Code:
MyStrCmd = System.Text.Encoding.ASCII.GetString(MemStream.ToArray)
But I don't kno how to impliment this properly either, am I going in the right direction? I don't know what to convert this text too, help?
guess ill grab another coffee..
Re: Using a string to script a line in my app
I think you'll find that's not possible. You can do it in scripting languages, but .NET source is compiled.
Maybe you could have a bunch of flags in your command file, like Close=True. You could put a filesystem watcher on the file, and when it gets modified you could evaluate each flag in the file.