bas7ex.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.
CLOSE, FREEFILE, and OPEN Programming 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.
 
DIM Filenum AS INTEGER
CLS
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 the file.
CLOSE Filenum%
 
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%
'Remove the file from disk.
KILL filename$