QBasic 1.1: GET (File I/O) Statement
Explanation
GET, PUT Statements (File I/O)
GET reads from a file into a random-access buffer or variable.
PUT writes a variable or random-access buffer to a file.
Worth knowing
Useful and cross-version information about the programming environments of QBasic, QuickBasic and Visual Basic for DOS.
Syntax
GET [#]filenumber%[,[recordnumber&][,variable]] |
PUT [#]filenumber%[,[recordnumber&][,variable]] |
Description / Parameter(s)
filenumber% |
The number of an open file. |
recordnumber& |
For random-access files, the number of the record to read or write. For binary-mode files, the byte position where reading or writing starts. |
variable |
For GET, a variable used to receive input from the file. For PUT, a variable that contains output to write to the file. The variable is usually a variable of a user-defined data type. |
Example
TYPE TestRecord
Student AS STRING * 20
Score AS SINGLE
END TYPE
DIM MyClass AS TestRecord
OPEN "FINAL.DAT" FOR RANDOM AS #1 LEN = LEN(MyClass)
MyClass.Student = "MarySa"
MyClass.Score = 99
PUT #1, 1, MyClass
CLOSE #1
OPEN "FINAL.DAT" FOR RANDOM AS #1 LEN = LEN(MyClass)
GET #1, 1, MyClass
PRINT "STUDENT:", MyClass.Student
PRINT "SCORE:", MyClass.Score
CLOSE #1
KILL "FINAL.DAT"