AboutDon Schullian Expertise I`ve worked in BASIC since the Commodore days and maintain a web site part of which is devoted to helping others with thier problems. I`m proficient in all versions of PowerBASIC but cross over to QuickBASIC and Qbasic frequently.
Expert: Don Schullian Date: 6/28/2008 Subject: Creating files from QuickBasic programs
Question Hi, it's me again, and I need another help.
I know there's a statement to create a file from your program, and another to delete it, thus using them to make a temporary inventory file with APPEND. Problem is, I only remember the statement to delete it (KILL), and I couldn't find anything on the net.
Oh, and just another thing: If I want to add an item to the inventory, I would use APPEND then PRINT and it would go to a new line, but if the player loses said file, how would I be able to delete the line? Reaching it is not a problem, I have already created a sub that goes from the first line (SEEK 1,1) to the last (EOF) looking for a certain line, stopping at it.
Thanks,
Eric
Answer Hi Eric,
It is said that the 2ed thing to go once you're past 50 is your memory and I saw 50 a decade ago so I'm going to do some guessing here as to what you're talking about. ;)
One creates a SEQ file with the OPEN statement (see help). What you want to be careful of is that when you open an already existing file in SEQ in other than APPEND or READ ONLY modes it overwrites the existing data! You may want to test the existence of the file before continuing. This is easily done by opening the file in BINARY mode and using LOF. Something like this:
FUNCTION fFileExists% ( FileSpec$ )
OPEN FileSpec$ FOR BINARY AS #128
L& = LOF(128)
CLOSE #128
IF L& = 0 THEN
KILL FileSpec$ ' This is optional if you're opening in SEQ
ELSE
fFileExist% = -1
END IF
END FUNCTION
Deleting a single item (line) from a SEQ file requires that you:
open a temp file
copy the lines you want to keep from the original file
close both files
delete the original file
rename the temp file to original name
open (new) original file
This is why it would be a good idea to hold the data in memory (string array?) if you're 100% sure that it wont exceed 64k.