Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
clearing a record question
#11
na_th_an:

I understand what you are saying. But you are not understanding what I am asking. I do not want to delete or remove the record from the file. I only want to clear the values that are currently in the teamrecord...not in the file.
Reply
#12
type teamrecord
teamid as string * 12
teamname as string * 25
.......
.......
end type
dim team as teamrecord


team.teamid=""
team.teamname=""
team......
team......



If you have a DIMed array you could do:

type teamrecord
teamid as string * 12
teamname as string * 25
.......
.......
end type
dim team(100) as teamrecord

index=50 'record to clear

team(index).teamid=""
team(index).teamname=""
team(index)......
team(index)......




This is really the only way, unless you use ERASE, which will clear the entire array if you use it.
Reply
#13
Thanks Z!re
That is what I thought, but was wondering if there was another way.
Reply
#14
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)
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#15
If you just want to clear a UDT, declare a second instance of it and don't mess with it; then when you want to clear another one, just assign the empty record to it. Like this:

Code:
TYPE t
a AS INTEGER
b AS STRING * 2
c AS DOUBLE
END TYPE

DIM rec AS t
DIM emptyrec AS t
...
rec.a = 3
rec.b = "hi"
rec.c = 2.7
...
' now empty rec
rec = emptyrec
Reply
#16
Thanks, that is pretty much what I was trying to ask.
Reply
#17
Again, that is not worth. Memory keeps being used. So there is no use on clearing the values, you are not saving memory.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#18
Quote:... I have a masterfile program that inputs and changes data. I have written it so that if it is decided to change data and the return key is pressed, that data field is not changed. My problem is, after one record is entered, and you go into adding another record, the data from the previous record is still in the type record (team). What is the best way to clear out the teamrecord?? Should I erase team and then dim it again after I put it??

The situation with the data from the previous record is called UNDERLAY. I personally don't use TYPE definitions so I can't offer you the best solution, but yes you need to clear out the record. One way to do this is to have another record defined with all the fields reset to null, zeros or blanks as you require. Then move this¨"reset" record to your regular record when you need it. And don't get confused about speed and wasting memory.
*****
Reply
#19
640 Kb is a very limited space. The more you do to save memory the best. Imagine you are doing a database for a school, in where you need to store name, address, birth date, phone number and 9 qualifications. Each record can take up to 500 bytes, that means that the max. num of students you can store in an array goes a bit over 128. If you delete a record just clearing it up, then you can store 1 pupil less, and the number decreases which each deletion, so it is better to have a way to tell the DBS that a record has been deleted and can be overwritten with new data.

Databases tend to grow fast. Limiting even more a yet very limited environment is not a good idea.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#20
Nathan, Everything you say about databases is true, except we're are not using any database system in this thread.

Also, you talk about keeping multiple pupil data in an array. Why on earth would you want to do it that way? Why can't you handle one pupil per record? --- like normal.

¿Que pasa, no te sientes bien?
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)