BBS: Inland Empire Archive Date: 05-22-92 (13:11) Number: 176 From: TIM FITZGERALD Refer#: NONE To: JIM TANNER Recvd: NO Subj: Deleting records in 1/ Conf: (2) Quik_Bas
JT>I have a program that creates individual records in a
JT>Random file. I would like to be able to go in and delete
JT>some of the records and then have the record numbers
JT>updated/revised so there is no skip (in the numbers) where
JT>the deleted records were.
I'm sure you will probably get a response, and code, that
surpasses mine.. but here's something I adapted from a routine
that I use.
___-------------------------------------------------------------
DECLARE SUB PreInit ()
DECLARE SUB DelRecord (Choice%)
DECLARE SUB CursKey (Row%, SRow%, ERow%, Col%, Sel%)
' Setup the Record structure with a TYPE .. END TYPE function.
' Works better than FIELD, I think.
TYPE Record
Client AS STRING * 15
Phone AS STRING * 12
END TYPE
DIM SHARED Rec AS Record
' Create some variables to hold the values of our record.
' Better than constantly reading them from disk, and faster.
' The (1 TO 10) will decide how many records you will allow
' in memory.
DIM SHARED MemRecClient(1 TO 10) AS STRING
DIM SHARED MemRecPhone(1 TO 10) AS STRING
DIM SHARED RecordCount%
PreInit ' This routine is just used to create a new file
' you can remove it after the first run.
RecordCount% = 10
Start:
CLS
PRINT " Name", "Phone Number"
PRINT " ----", "------------"
PRINT
FOR count% = 1 TO RecordCount%
LOCATE 3 + count%, 4
PRINT MemRecClient(count%), MemRecPhone(count%)
NEXT count%
LOCATE RecordCount% + 5, 4: PRINT "Press ESC to Quit DEMO"
CursKey 4, 4, RecordCount% + 3, 1, Sel%
DelRecord (Sel%)
GOTO Start
SUB CursKey (Row%, SRow%, ERow%, Col%, Sel%)
Place:
LOCATE Row%, Col%
PRINT "=>"
a$ = ""
WHILE a$ = ""
a$ = INKEY$
IF a$ = CHR$(0) + CHR$(80) THEN
IF Row% < ERow% THEN
LOCATE Row%, Col%: PRINT " "
Row% = Row% + 1
END IF
END IF
IF a$ = CHR$(0) + CHR$(72) THEN
IF Row% > SRow% THEN
LOCATE Row%, Col%: PRINT " "
Row% = Row% - 1
END IF
END IF
IF a$ = CHR$(13) THEN GOTO Done
IF a$ = CHR$(27) THEN KILL "TEMP.DAT" :END
WEND
GOTO Place
Done:
Sel% = Row%
END SUB
SUB DelRecord (Choice%)
FOR DRecord% = Choice% TO RecordCount%
IF DRecord% = RecordCount% THEN EXIT FOR
SWAP MemRecClient(DRecord%), MemRecClient(DRecord% + 1)
SWAP MemRecPhone(DRecord%), MemRecPhone(DRecord% + 1)
NEXT DRecord%
KILL "temp.dat"
OPEN "temp.dat" FOR RANDOM AS #1 LEN = 27
FOR count% = 1 TO RecordCount% - 1
LET Rec.Client = MemRecClient(count%)
LET Rec.Client = MemRecPhone(count%)
PUT #1, count%, Rec
NEXT count%
CLOSE #1
RecordCount% = RecordCount% - 1
END SUB
SUB PreInit
FOR count% = 1 TO 10
MemRecClient(count%) = "Guy " + STR$(count%)
MemRecPhone(count%) = "111-222-" + STR$(count%)
NEXT count%
OPEN "temp.dat" FOR RANDOM AS #1 LEN = 27
FOR count% = 1 TO 10
LET Rec.Client = MemRecClient(count%)
LET Rec.Phone = MemRecPhone(count%)
PUT #1, count%, Rec
NEXT count%
CLOSE #1
END SUB
___-------------------------------------------------------------
You may want to ignore the CursKey routine, I just through that
together. I think the main thing is the usage of SWAP..
BTW, the LISTBOX.BAS routine, by Matt Hart, would work great in
place of my CursKey throwup. All you would have to do is adjust
the "MemRecClient" and the "MemRecPhone" limits.
>>> Continued to next message
___
X OLX 2.1 TD X Press "+" to see another tagline.
--- Maximus 2.01wb
* Origin: The Chatter Box ** Baker, La. (1:3800/18)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET