Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

A command in a string?

How can I make QBasic to do a command which is in a string?

I did think about writing the command into another bas file, but how should I make exe files??




Comments

  • : How can I make QBasic to do a command which is in a string?

    : I did think about writing the command into another bas file, but how should I make exe files??

    I've been working with a similar problem,

    which is turning a string into an equation. The

    solution I've come up with will not work in Qbasic,

    because the metacommand (whatever that means)

    $INCLUDE is not supported in Qbasic, only in

    QuickBasic. What I do is I read the string

    from the keyboard and write it to a file, then use

    the RUN command to execute a different program which

    includes the file using the $INCLUDE metacommand.

    You can't modify the file you're including in the

    same program, the changes won't take effect.

    Does anyone else have any ideas on how

    to insert an inputted string into a program as it

    is running? My solution is pretty clumsy.




  • If it's standard QBasic code (no user-named functions or anything like that), then you can simply translate it.

    For example, assume you have the following line:


    Open "C:Autoexec.bat" For InPut As 1


    then part of the "translate" code could be:


    If UCase$(Left$(CommandLine, 4)) = "OPEN" Then

    CommandLine = Right$(CommandLine, Len(CommandLine) - 6)

    FileName = Left$(CommandLine, InStr(1, CommandLine, Chr$(34) - 1)

    CommandLine = Right$(CommandLine, Len(CommandLine) - (Len(FileName) + 6))

    'Get the file number

    FFile = Val(Right$(CommandLine, Len(CommandLine) - InStr(1, UCase$(CommandLine), " AS ") - 3))

    CommandLine = Left$(CommandLine, InStr(1, UCase$(CommandLine), " AS ") - 1)

    'Now get the file mode and open

    Select Case UCASE$(CommandLine)

    Case "INPUT"

    Open FileName For InPut As FFile

    Case "BINARY"

    Open FileName For Binary As FFile

    Case ...

    ...

    End Select


    It's a bit crude and any code long enough to recognize the whole language probably can't be compiled (too big), but if you only intend to allow a few commands, then this might be what you need. And it might even work! (I wrote without testing it).


    Later,


Sign In or Register to comment.