Qbasicnews.com
READing from an opened file - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: READing from an opened file (/thread-975.html)



READing from an opened file - Roadkill - 05-27-2003

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.


READing from an opened file - na_th_an - 05-27-2003

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.


READing from an opened file - Roadkill - 05-28-2003

hmm good good. i think you solved my problem


READing from an opened file - seph - 05-28-2003

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%