CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    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.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  2. #2
    Join Date
    May 1999
    Posts
    3,332

    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.


  3. #3
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    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.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  4. #4
    Join Date
    May 1999
    Posts
    3,332

    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






  5. #5
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    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
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured