Qbasicnews.com

Full Version: READing from an opened file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i have a 32 by 32 DATA statement in a seperate file. how could i open that file, read the data, put it on the screen and get it?
or would it be easier to just put the data in my program.
(soon the file will contain close to 30 of these 32x32 bitmaps as i make new tiles for my application.
It would be easier to put that in your command.

If you still want to use the file as external, remove the "DATA" statements and leave just the numbers:

Code:
4, 5, 6, 4, 3, ...
4, 3, 1, 2, ...

for example. Then you can read it using OPEN and the like:

Code:
f%=FREEFILE
OPEN "MyFile.txt" FOR INPUT AS #f%
FOR i%=1 TO 32
   FOR j%=1 TO 32
      INPUT #f%,c%
      PSET (j%-1, i%-1), c%
NEXT j%,i%
CLOSE #f%

It would be better if you posted the file so we can see the format it has.
hmm good good. i think you solved my problem
Or you could shorten the program a few characters...

Code:
f%=FREEFILE
OPEN "MyFile.txt" FOR INPUT AS #f%
FOR i%=0 TO 31
   FOR j%=0 TO 31
      INPUT #f%,c%
      PSET (j%, i%), c%
NEXT j%,i%
CLOSE #f%