'Random length string database creation.
'This demo will utilize two different files to manage our database.
'the first one will be the data, and the second will be our index to the data
LengthName
AS LONG 'track how long the name is LengthSex
AS LONG 'track how long the sex is LengthPhone
AS LONG 'track how long the phone is
RecordCount
= LOF(2) \
LEN(Index
)RecordNumber = 1
choice = ShowOptions
CASE 5: RecordNumber
= RecordNumber
- 1:
IF RecordNumber
< 1 THEN RecordNumber
= RecordCount
CASE 6: RecordNumber
= RecordNumber
+ 1:
IF RecordNumber
> RecordCount
THEN RecordNumber
= 1
IF RecordNumber
> 0 AND RecordNumber
<= RecordCount
THEN 'Get the current record and display it GET #2, (RecordNumber
- 1) * LEN(Index
) + 1, Index
Record.Sex
= SPACE$(Index.LengthSex
) Record.Phone
= SPACE$(Index.LengthPhone
) GET #1, Index.StartPosition
, Record.
NAME Record.
NAME = "DELETED RECORD" Record.Age = 0
Record.Sex = ""
Record.Phone = ""
Record.
NAME = "NO RECORD" Record.Age = 0
Record.Sex = ""
Record.Phone = ""
PRINT "Steve's Variable Length Database Demo" PRINT "Record Number "; RecordNumber;
" of "; RecordCount
PRINT "Age : "; Record.Age
PRINT "Sex : "; Record.Sex
PRINT "Phone: "; Record.Phone
RecordNumber = 0 'Display a blank record
ShowMainInfo
RecordCount = RecordCount + 1 'increase our total count of records
RecordNumber = RecordCount 'And set our current record to the new record count value
filesize
= LEN(Record.
NAME) + LEN(Record.Age
) + LEN(Record.Sex
) + LEN(Record.Phone
) Index.Valid = -1
Index.StartPosition
= LOF(1) + 1 Index.LengthName
= LEN(Record.
NAME) Index.LengthSex
= LEN(Record.Sex
) Index.LengthPhone
= LEN(Record.Phone
) PUT #2, (RecordCount
- 1) * LEN(Index
) + 1, Index
t$
= Record.
NAME:
PUT #1, Index.StartPosition
, t$
'We must use a temp string, as we can't put a variable length string type to a file t$
= Record.Sex:
PUT #1, , t$
t$
= Record.Phone:
PUT #1, , t$
ShowMainInfo
oldfilesize
= LEN(Record.
NAME) + LEN(Record.Age
) + LEN(Record.Sex
) + LEN(Record.Phone
)
filesize
= LEN(Record.
NAME) + LEN(Record.Age
) + LEN(Record.Sex
) + LEN(Record.Phone
) Index.Valid = -1
IF filesize
> oldfilesize
THEN 'if our edit is larger than our old data Index.StartPosition
= LOF(1) + 1 'we have to put it at the end of the existing datafile END IF 'otherwise,we just put it where it currently exists Index.LengthName
= LEN(Record.
NAME) Index.LengthSex
= LEN(Record.Sex
) Index.LengthPhone
= LEN(Record.Phone
) PUT #2, (RecordNumber
- 1) * LEN(Index
) + 1, Index
t$
= Record.
NAME:
PUT #1, Index.StartPosition
, t$
'We must use a temp string, as we can't put a variable length string type to a file t$
= Record.Sex:
PUT #1, , t$
t$
= Record.Phone:
PUT #1, , t$
Index.Valid = 0
PUT #2, (RecordNumber
- 1) * LEN(Index
) + 1, Index
Index.Valid = -1
PUT #2, (RecordNumber
- 1) * LEN(Index
) + 1, Index
ShowMainInfo
PRINT "2) Delete Current Record" PRINT "3) Undelete Current Record" PRINT "4) Edit Current Record" PRINT "5) Previous Record"