qb45advr.hlp (
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
SEEK Statement Programming Example
◄QuickSCREEN► ◄Details► ◄Example► ◄Contents► ◄Index►
──────────────────────────────────────────────────────────────────────────────
SEEK Statement Programming Example
The following program uses a combination of the SEEK function and SEEK
statement to move the file position exactly one record back and rewrite
the record if a variable is true (nonzero).
'*** Programming example for the SEEK function and statement
'
CONST FALSE=0, TRUE=NOT FALSE
' Define record fields.
TYPE TestRecord
NameField AS STRING * 20
ScoreField AS SINGLE
END TYPE
' Define a variable of the user type.
DIM RecordVar AS TestRecord
'********************************************************************
' This part of the program is an insert whose only function is to
' create a random-access file to be used by the second part of the
' program, which demonstrates the CVSMBF function
'********************************************************************
OPEN "TESTDAT2.DAT" FOR RANDOM AS #1 LEN = LEN(Rec)
CLS
RESTORE
READ NameField$, ScoreField
I = 0
DO WHILE UCASE$(NameField$) <> "END"
I = I + 1
RecordVar.NameField = NameField$
RecordVar.ScoreField = ScoreField
PUT #1, I, RecordVar
READ NameField$, ScoreField
IF NameField$ = "END" THEN EXIT DO
LOOP
CLOSE #1
'
DATA "John Simmons", 100
DATA "Allie Simpson", 95
DATA "Tom Tucker", 72
DATA "Walt Wagner", 90
DATA "Mel Zucker", 92
DATA "END", 0
' Open the test data file.
'
DIM FileBuffer AS TestRecord
OPEN "TESTDAT2.DAT" FOR RANDOM AS #1 LEN=LEN(FileBuffer)
' Calculate number of records in the file.
Max = LOF(1) / LEN(FileBuffer)
' Read and print contents of each record.
FOR I = 1 TO Max
GET #1, I, FileBuffer
IF FileBuffer.NameField = "Tom Tucker" THEN
ReWriteFlag = TRUE
EXIT FOR
END IF
NEXT I
'
IF ReWriteFlag = TRUE THEN
' Back up file by the length of the record variable that
' is used to write to the file.
FileBuffer.ScoreField = 100
SEEK #1, SEEK(1) - LEN(RecordVar)
PUT #1 , , RecordVar
END IF
'
CLOSE #1
KILL "TESTDAT2.DAT"
END