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.
OPEN Statement
  Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
Opens a file or device.
 
OPEN file$ [FOR mode] [ACCESS access] [lock] AS [#]filenumber% [LEN=reclen%]
 
    ■ file$          The name of the file or device. The file name may
                     include a drive and path.
    ■ mode           One of the following file modes: APPEND, BINARY, INPUT,
                     OUTPUT, or RANDOM. See OPEN Statement File Modes.
    ■ access         In network environments, specifies whether the file is
                     opened for READ, WRITE, or READ WRITE access.
                     See OPEN Statement ACCESS Clause.
    ■ lock           Specifies the file locking in network environments:
                     SHARED, LOCK READ, LOCK WRITE, LOCK READ WRITE.
    ■ filenumber%    A number in the range 1 through 255 that identifies the
                     file while it is open.
    ■ reclen%        For random-access files, the record length (default is
                     128 bytes). For sequential files, the number of
                     characters buffered (default is 512 bytes).
 
Example:
    INPUT "Enter Filename: "; n$
    OPEN n$ FOR OUTPUT AS #1
    PRINT #1, "This is saved to the file."
    CLOSE
    OPEN n$ FOR INPUT AS #1
    INPUT #1, a$
    PRINT "Read from file: "; a$
    CLOSE
 
See Also    CLOSE    FREEFILE    OPEN COM    TYPE
            OPEN Statement Alternate Syntax