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 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"