Reading commands from file
I'm just wondering...
a) is it possible to read input form a file, and them let VB interpret them as actual commands.
Like say a file contain 3 lines, t=t+1, t=t+2, t=t+3.
Is there a way to do this without having to break up the line in small parts and then evaluate them one by one to form the command.
b) is it possible to add a module at run time? Like I have a program that reacts on a specified event with actions defined by the user. These commands are to be placed in a .bas file.
Thanx in advance
Tom Cannaerts
[email protected]
The best way to escape a problem, is to solve it.
Re: Reading commands from file
all these things can be done by using the "microsoft Script control".
here is my answer to a post from last week about the same thing:
private Sub Command1_Click()
Dim hFile as Integer
hFile = FreeFile
Dim strLine as string
Open "c:\test.txt" for input as #hFile
Do While Not EOF(hFile)
Line input #hFile, strLine
s.ExecuteStatement strLine
Loop
Close (hFile)
End Sub
contents of test.txt
msgbox "hello.world"
msgbox "greetings from the script control"
the script control allows you to add modules, too.
Re: Reading commands from file
Thanx for the reply, one question however (because I haven't vb around here):
Using the s.ExecuteStatement, can it handle loops (like for, do) and mulptiple-line if-statements?
Tom Cannaerts
[email protected]
The best way to escape a problem, is to solve it.
Re: Reading commands from file
here is a sample:
private Sub Command1_Click()
Dim c as string
c = "sub test" & vbCrLf & "if a = b then" & vbCrLf & _
"msgbox ""hello, world""" & vbCrLf & _
"end if" & vbCrLf & "end sub"
s.AddCode c
s.ExecuteStatement "a=5" & vbCrLf & "call test"
s.ExecuteStatement "b=5" & vbCrLf & "call test"
End Sub
A bit of knowledge From Past
;-)
Have a nice day, wherever.
Cesare
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater