Click to See Complete Forum and Search --> : Reading commands from file


Cakkie
February 21st, 2000, 12:23 AM
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
slisse@planetinternet.be

The best way to escape a problem, is to solve it.

Lothar Haensler
February 21st, 2000, 01:34 AM
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.

Cakkie
February 21st, 2000, 01:46 AM
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
slisse@planetinternet.be

The best way to escape a problem, is to solve it.

Lothar Haensler
February 21st, 2000, 01:52 AM
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

Cimperiali
April 9th, 2002, 05:57 AM
;-)

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