Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deleting variables in a file
#1
I know that you can use the KILL statement to delete a file from your hard drive within Qbasic, but if I wanted to remove a variable from a sequential file, how would I do that? Use the KILL command?

Thanks.
Reply
#2
WOW!!
NOOO!!

Smile

KILL erases files, not records inside a file. To delete a record from a secuential file, you have to open it, read it, and write it again to an emplty file without adding that record. For example, let's say that you want to erase value "99" from an integer sequential file (for example). The file is NUMBERS.DAT

Code:
OPEN "NUMBERS.DAT" FOR INPUT AS #1
OPEN "NUMBERS.2" FOR OUTPUT AS #2
WHILE NOT EOF(1)
   INPUT #1, number%
   IF number% <> 99 THEN PRINT #2, number%
WEND
CLOSE
' Now we KILL the original file
KILL "NUMBERS.DAT"
' And we change the name of the new file:
NAME "NUMBERS.2" AS "NUMBERS.DAT"
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
If it's a file of records:
-Seek the position of the record
-mark the record as empty by overwriting it with an impossible value.

..This way you don't need to rewrite the whole file.

Next time you read the file just remember the impossible value means a deleted record and skip it each time you find it.
Antoni
Reply
#4
Just wrap the whole file to the front then, instead of leaving a blank space. 8)
Reply
#5
How would I go about "wrapping" to the front?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)