open/read/write to a flat file
Posted: Thu Mar 06, 2008 2:24 pm
Sorry to bother everyone, I'm new to QB and need a little help. I have gotten to a point where I need to store data and I figure the easiest way to do so would be to write/read to a flat file. What I could find only worked partly. I am able to OPEN the file or create it if it doesn't exist by doing the following.
DIM fh AS STRING
fh = FREEFILE
OPEN "PLANTS.DAT" FOR RANDOM AS #fh
This seems to work, it will create the file if it doesn't exist. My problem comes in at trying to write to the file and read from it. I have been trying the following line that goes with the above example.
PRINT #fh, "This should be line 1"
but that doesn't seem to write anything to the file. Any idea's on this? I am using QuickBasic 4.5 running XP PRO and I don't have any problems with other QB programs running on XP so I don't think that's it.
While I have you. If you know how to read a line from a file then parse it, it would be helpful :P
In the above example I am wanting to write lines to the file that will look like:
100:PLANT1
200:PLANT2
and so on... When I read the information back I need to be able to read a line and parse it by the delimiter.. in this case : ... It can be a comma if it has to be, that doesn't really matter.
Thanks for the help in advance!
DIM fh AS STRING
fh = FREEFILE
OPEN "PLANTS.DAT" FOR RANDOM AS #fh
This seems to work, it will create the file if it doesn't exist. My problem comes in at trying to write to the file and read from it. I have been trying the following line that goes with the above example.
PRINT #fh, "This should be line 1"
but that doesn't seem to write anything to the file. Any idea's on this? I am using QuickBasic 4.5 running XP PRO and I don't have any problems with other QB programs running on XP so I don't think that's it.
While I have you. If you know how to read a line from a file then parse it, it would be helpful :P
In the above example I am wanting to write lines to the file that will look like:
100:PLANT1
200:PLANT2
and so on... When I read the information back I need to be able to read a line and parse it by the delimiter.. in this case : ... It can be a comma if it has to be, that doesn't really matter.
Thanks for the help in advance!