Qbasicnews.com

Full Version: Writing to the same line in the same file in a loop?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey all,

I'm trying to write to the 1st line continously in a DO...LOOP, but instead it just writes line after line. I also tried using the SEEK command..I guess used that for the wrong use, it just leaves boxes. Here's my code

Code:
OPEN "testing.dat" FOR APPEND AS #1
DO
pie = int(rnd * 50) + 1
WRITE #1, pie
LOOP while inkey$ = ""
END

'thats the loop that writes line after line

OPEN "testing.dat" FOR APPEND AS #1
DO
pie = int(rnd * 50) + 1
SEEK #1, 1 'this doesnt leave it at the first line, does it?
WRITE #1, pie
LOOP while inkey$ = ""
END

'thats the loop that leaves black boxes..

So...anyone know how to solve my problem here...I'm trying to write on line, preferrably using commas between each pie variable..thanks!
Code:
OPEN "testing.dat" FOR APPEND AS #1
first = 1
DO
  pie = int(rnd * 50) + 1
  IF first THEN
    first = 0
  ELSE
    PRINT #1, ",";
  END IF
  PRINT #1, pie;
LOOP while inkey$ = ""
CLOSE #1
END
Thanks a lot Plasma!