1. question converting to euphoria from qbasic

I have been doing pretty good in converting over between the two languages,
but I'm stuck on how to transfer the following basic chunk to a Euphoria
chunk.

OPEN "c:\file.txt" FOR OUTPUT AS #1
DO
IF EOF(1) THEN GOTO 1090
LINE INPUT #1, d$
PRINT d$
LOOP
1090 SLEEP
END

new topic     » topic index » view message » categorize

2. Re: question converting to euphoria from qbasic

At 09:22 AM 4/11/98 EDT,  ST Qu Man  wrote:

>Subject:      question converting to euphoria from qbasic
>-------------------------------------------------------------------------------
 I'm stuck on how to transfer the following basic chunk to a Euphoria chunk.
>
>OPEN "c:\file.txt" FOR OUTPUT AS #1
>DO
>IF EOF(1) THEN GOTO 1090
>LINE INPUT #1, d$
>PRINT d$
>LOOP
>1090 SLEEP
>END
>
Euphoria can duplicate this with one line:
puts(1,"Bad file mode") abort(1)

Seriously, if you change the file mode to INPUT, you
can write it as follows:

include get.e   -- for wait_key
atom fn           -- storage for file handle
object line_in  -- storage for line input

  fn = open("c:\\file.txt","r")   -- "r" is read mode (text)
  while 1 do                         -- same as loop forever
     line_in = gets(fn)            -- read a line in
     if atom(line_in) then exit -- eof, so end loop
     else puts(1,line_in)         -- otherwise, print it
     end if
  end while
  fn = wait_key()  -- wait here for keypress (same as SLEEP)
                           -- if you want to replace SLEEP n,
                           -- where n is a number of seconds to wait,
                           --you need to write a little time delay routine
                           -- instead.
----------------------------------------------------------
--Visit my Euphoria programming web site:--
--http://www.mindspring.com/~mountains   --
----------------------------------------------------------

new topic     » goto parent     » topic index » view message » categorize

3. Re: question converting to euphoria from qbasic

At Sat, 11 Apr 1998 09:22:41 EDT, ST Qu Man <STQuMan at AOL.COM> asked:
>how to transfer the following basic chunk to a Euphoria chunk.
>
>OPEN "c:\file.txt" FOR OUTPUT AS #1
>DO
>IF EOF(1) THEN GOTO 1090
>LINE INPUT #1, d$
>PRINT d$
>LOOP
>1090 SLEEP
>END

Assuming OUTPUT is changed to INPUT, all the solutions that have been
posted by BASIC-as-well-as-Euphoria programmers here [blink] seem to be
correct (I haven't tried them though), but then I noticed:

At Sun, 12 Apr 1998 18:02:08 GMT, Jeff Zeitlin
<jeff.zeitlin at MAIL.EXECNET.COM> replied:
>Really, what you're doing is reading each line of the file and
>printing it to the screen - essentially, the equivalent of the
>DOS built-in TYPE command.

So I thought I'd offer a simpler one-command replacement:

    system("type c:\\file.txt", 1)  -- bonus: beep and clear screen blink

Since that doesn't do the task nicely (it clears the screen), how about a
two-command one:

    system("type c:\\file.txt", 2)
    system("pause >nul", 2)

If you can't afford two system calls, with three commands you can say:

    include get.e
    system("type c:\\file.txt", 2)
    abort(wait_key())   -- this will also abort the program

If you don't want to abort the system call and don't want to use the DOS
pause command, you need four commands:

    include get.e
    integer i
    system("type c:\\file.txt", 2)
    i = wait_key()

Why do I prefer using system? Because I haven't registered Euphoria, I
can't afford it (how about my suggestion on having an Euphoria programming
contest, a really nice award is a registered version of Euphoria and I
really want it), and I have to constantly find tricks to keep my programs
having as few statements as possible (because 300 is just too small a limit
to let me program freely and creatively).

Note that there is a difference between all the Euphoria implementations
(including above) and the OUT-to-IN fixed QBasic program: the SLEEP command
will wait for a key (it does not return it, but it does not matter), and
you can even wake up from the SLEEP command by using keys like Shift, Ctrl
or Alt, but this cannot be done easily in Euphoria [not with wait_key, nor
with system("pause")].
--> Any idea to have such a SLEEP command?

new topic     » goto parent     » topic index » view message » categorize

4. Re: question converting to euphoria from qbasic

how about system("Type c:\\file.txt|more",2)  ?:-]

NEW! HTTP://www.geocities.com/SiliconValley/Lab/7577
Michael J Raley's Modular Reality Journal

>>Really, what you're doing is reading each line of the file and
>>printing it to the screen - essentially, the equivalent of the
>>DOS built-in TYPE command.
>
>So I thought I'd offer a simpler one-command replacement:
>
>    system("type c:\\file.txt", 1)  -- bonus: beep and clear screen blink
>
>Since that doesn't do the task nicely (it clears the screen), how about a
>two-command one:
>
>    system("type c:\\file.txt", 2)
>    system("pause >nul", 2)

new topic     » goto parent     » topic index » view message » categorize

5. Re: question converting to euphoria from qbasic

I suggested:
>>    system("type c:\\file.txt", 2)
>>    system("pause >nul", 2)

At Mon, 13 Apr 1998 21:07:43 -0700,
Michael Raley <mjronline at IT-WORKS.COM> replied:
>how about system("Type c:\\file.txt|more",2)  ?:-]

That's different, it doesn't pause after the last line of text (and it uses
MORE, an external command). Even if that is what is required, I'd rather use
    system("more<c:\\file.txt", 2)
than your example, since it's faster and doesn't require a disk write (!).

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu