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.
CLOSE, OPEN Statements and FREEFILE Function Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
' This example uses FREEFILE to obtain the next available file number. It
' uses the OPEN statement to open a sequential file, the CLOSE statement
' to close the file, and the KILL statement to delete the file from the
' disk.
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
DIM Filenum AS INTEGER
CLS ' Clear the screen
INPUT "Enter file name: ", filename$
Filenum% = FREEFILE
OPEN filename$ FOR OUTPUT AS Filenum%
PRINT : PRINT UCASE$(filename$); " opened for output as File #"; Filenum%
' Put something in the file.
PRINT #Filenum%, "The quick brown fox jumped over the lazy yellow dog."
CLOSE Filenum% ' Close the file
Filenum% = FREEFILE
OPEN filename$ FOR INPUT AS Filenum%
PRINT : PRINT UCASE$(filename$); " has been reopened for input."
LINE INPUT #Filenum%, L$
PRINT : PRINT "The contents of the file are:"; L$
CLOSE Filenum%
KILL filename$ ' Remove the file from disk