Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 5

Program File

A program is a collection of instructions written in a computer language. After writing the program in
the computer, it can be stored in the secondary storage device (hard disk) as a file, which is called
program file. A program file contains instructions, which are used to manipulate data and give the
output. In the previous chapters, we have written many programs and stored them in the hard disk,
which are called program files.
Data File
The data can be name, number, address, salary, post, etc., which are stored in a disk under a filename, known as data
file. A data file is a collection of the related data stored in the hard disk or any other secondary storage devices
separately from the program that uses it.

In the previous chapters, we have learnt to provide data to the program using different statements of QBASIC, such as
INPUT, READ and LET statements.
These statements have some disadvantages:
 The data supplied from the keyboard using the above statements are not stored permanently; they are erased when a
new program is started or a program is re-executed or the computer is turn off.
 It is difficult to handle a large amount of data.
 The data stored in one program cannot be used in another program.

To overcome these disadvantages, QBASIC provides a method of creating a data file through which the data can be
stored permanently on the disk. A data file can be opened, and data can be written, saved and then closed.

Advantages of Data file


 Once a data file is created, it can be reused.
 Different programs can share the same data file.
 It can be created, modified or deleted.
 It can be used to store output for the future use.
 A data file can store a large amount of data.
QBASIC supports two types of data file.
They are:
a. Random access data file
b. Sequential access data file

a. Random access data file

A random access data file conducts reading and writing operations randomly. It is
suitable for the database that requires direct access to individual records stored on
the disk. For example, to read 100th data item, one does not need to go through all
the data from 1 to 99. Data number 100 can be directly accessed without going
through other data items.
Sequential access data file

A sequential access data file conducts reading and writing operations sequentially,
from the beginning of the file to the end. For example, if you store 10 different data
and if you want to read, 9th data, then you will have to pass through the 1st to 8th
data to search the 9th data; there is no way to directly go to it. But to create
sequential data, file takes less program steps. It is a perfectly suitable medium for
any application that does not require direct access to any record.

Now, we will discuss the sequential access data file, its command and functions that
perform the following tasks:
 Opening a new sequential data file for writing purpose
 Writing data or information to open a file
 Opening a sequential file for reading purpose
 Reading data from the open file
 Opening an existing file to append the data or information to the end of the file
 Closing the data file after operations are over

You might also like