Opening sequential file

Sequential access works best when you want to process files consisting only of text, such as the files created with a typical text editor — that is, files in which data is not divided into a series of records. Sequential access may not be well suited for storing long series of numbers, because each number is stored as a character string. A four-digit number would require 4 bytes of storage instead of the 2 bytes it requires to store the same number as an integer.


Opening Files for Sequential Access
When you open a file for sequential access, you open it to perform one of the following operations:

 

  • Input characters from a file (Input)
  • Output characters to a file (Output)
  • Append characters to a file (Append)

To open a file for sequential access, use the following syntax for the Open statement:


Open pathname For [Input | Output | Append] As filenumber [Len = buffersize]


1. When you open a sequential file for Input, the file must already exist; otherwise, an error occurs. 2. When you try to open a nonexistent file for Output or Append, however, the Open statement creates the file first and then opens it.
3. The optional Len argument specifies the number of characters to buffer when copying data between the file and your program.
4. After opening a file for an Input, Output, or Append operation, you must close it, using the Close statement, before reopening it for another type of operation.

 

Editing Files Opened for Sequential Access
If you want to edit a file, first read its contents to program variables, then change the variables, and finally, write the variables back to the file. The following sections discuss how to edit records opened for sequential access.

 

basic file handling by v. vanthana