bas7ex.hlp (Topic list)
PUT and TYPE Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example use the PUT statement to store test scores in a
'random-access file. The TYPE statement is used to create a
'user-defined variable type.
 
'Define record fields.
TYPE TestRecord
   NameField  AS STRING * 20
   ScoreField AS SINGLE
END TYPE
 
 
DIM FileBuffer AS TestRecord
DIM I AS LONG
 
'Open the test data file.
OPEN "TESTDAT.DAT" FOR RANDOM AS #1 LEN = LEN(FileBuffer)
 
 
'Read pairs of names and scores from the console.
CLS    'Clear screen.
I = 0
DO
    I = I + 1
    INPUT "Name ? ", FileBuffer.NameField
    INPUT "Score? ", FileBuffer.ScoreField
    INPUT "-->More (y/n)? ", Resp$
    PUT #1, I, FileBuffer
LOOP UNTIL UCASE$(MID$(Resp$, 1, 1)) = "N"
 
PRINT I; " records written."
 
CLOSE #1
 
'Remove file from disk.
KILL "TESTDAT.DAT"