Qbasicnews.com
November 13, 2019, 06:56:07 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Deleting variables in a file  (Read 3268 times)
joey7643
Member
*
Posts: 59


« on: January 29, 2003, 07:02:57 PM »

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.
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #1 on: January 29, 2003, 07:08:01 PM »

WOW!!
NOOO!!

Smiley

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"
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #2 on: January 29, 2003, 08:39:00 PM »

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.
Logged

Antoni
Neo
Na_th_an
*****
Posts: 2150



« Reply #3 on: January 30, 2003, 08:12:21 AM »

Just wrap the whole file to the front then, instead of leaving a blank space. Cool
Logged
joey7643
Member
*
Posts: 59


« Reply #4 on: January 30, 2003, 05:50:10 PM »

How would I go about "wrapping" to the front?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!