I understood your question completely, but you got puzzled when I told you that it was good to use my method if you were store stuff in a file. I was not talking about files, but about memory.
I'll explain it again: When you want to delete a record you mark it "empty" instead of putting it to "". When you have to write to a record, you check if it is "empty" and overwrite its contents. That way you save memory and time. Clearing the variables is not worth: the variables are still there but they equal "", plus you spend time clearing them.
Look:
Code:
TYPE rec
name AS STRING*20
age AS INTEGER
status AS INTEGER
END TYPE
CONST empty = 0
CONST nonEmpty = 1
CONST MaxElems = 100
DIM db(MaxElems) AS rec
SUB AddRecordToDatabase(db() AS rec, name$, age%)
' find first empty record:
inserted%=0
FOR i%=0 TO MaxElems
IF db(i%).status = empty THEN
' found an empty record.
db(i%).status = nonEmpty
db(i%).name = name$
db(i%).age = age%
inserted%=-1
EXIT FOR
NEXT i%
IF NOT inserted% THEN PRINT "Error! Database full :("
END SUB
SUB DeleteRecordFromDatabase(index%)
db(index%).status = empty
END SUB
When you want to add a record to the database you use the first SUB, which will find an empty "slot". To delete a record you call the second SUB.
You can compact your database doing something like this:
Code:
' This function compacts the database and returns the number of items in it.
SUB compact(db() AS rec, numItems%)
idx1%=0
idx2%=0
WHILE idx1%<=MaxItems
WHILE db(idx1%).status = empty
idx1%=idx1%+1
WEND
IF idx1%<>idx2% THEN
' copy record
db(idx2%)=db(idx1%)
ENDIF
idx2%=idx2%+1
idx1%=idx1%+1
WEND
numItems%=idx2%
END SUB
(disclaimer: wrote from the top of my head, may be slightly wrong)