Closing Data Files

As you may have guessed, closing a data file is an important part of file processing. Specifically, closing a data file performs the following operations:

• Writes the EOF marker

• When using the Output or Append mode, writes records to the physical file in the sequential order in which they were created

• Releases the file number and buffer for memory conservation

To close a data file, simply use the Close function after all file processing has completed.

Close #FileNumber

The Close function takes the file number as its only parameter. For example, to close the file quiz.dat after writing one record, I could use the Close function:

Open "quiz.dat" For Output As #1

Write #1, 1, "Is Visual Basic an Event Driven language?", "Yes" Close 1

If the Close function is used without any parameters, it closes all open sequential data files.

0 0

Post a comment