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.
PUT (File I/O) Statement Programming Example
  QuickSCREEN      Details     Example      Contents      Index
──────────────────────────────────────────────────────────────────────────────
PUT (File I/O) Statement Programming Example
 
This example reads names and test scores from the console and stores them
in a random-access file.
 
' Read a name and a test score from the console.
' Store each name and score as a record in a
' random-access file.
 
' Define record fields.
TYPE TestRecord
   NameField  AS STRING * 20
   ScoreField AS SINGLE
END TYPE
 
' Open the test data file.
DIM FileBuffer AS TestRecord
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