Opening a Sequential Data File

The first step in creating or accessing a data file is to open it. Microsoft provides an easy-to-use facility for opening a data file through the Open function.

Open "Filename" For {Input | Output | Append} As #Filenumber [Len = Record Length]

The Open function takes three parameters. Filename describes the name of the file you wish to open or create. Input|Output|Append is a list from which you pick one to use. #Filenumber is a number from 1 to 511 that is used for referencing the file. Len is an optional parameter that can control the number of characters buffered. The sequential access modes are shown in Table 7.2.

A sample data file.

I use the Open method to create a new file for output called quiz.dat. Open "quiz.dat" For Output As #1

Table 7.2 Sequential Access Modes

Mode Description

Input Reads records from a data file

Output Writes records to a data file

Append Writes or appends records to the end of a data file

0 0

Post a comment