qbasic.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.
GET, PUT Statements (File I/O)
  Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
GET reads from a file into a random-access buffer or variable.
PUT writes a variable or random-access buffer to a file.
 
GET [#]filenumber%[,[recordnumber&][,variable]]
PUT [#]filenumber%[,[recordnumber&][,variable]]
 
    ■ 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"
 
See Also    FIELD    GET, PUT (Graphics)    LSET, RSET
            MKn$, CVn Functions               TYPE