FILE HANDLING IN QBASIC


#File: A file is a collection of related information that is stored in a disk under a unique file name.

A file can be categorized as:

(i)Data file

(ii)Program file

1.Data File: A data file contains real data of any person, thing or entity. The data is stored under different attributes such as name, address, phone, etc.

2.Progam File: A program file consists of set of program codes and instructions. The instructions are written in a computer language. Program files in QBASIC have extension .BAS.

#File Handling: It is a process to create a data file, write data to the data file and read data from the specified data file.

Types of data files in QBASIC:

(i)Sequential data file

(ii)Random access data file

1.Sequential data file: In a sequential access data file, data are stored in

sequential order.

·        Performs reading and writing sequentially from the beginning to the end of a file.

·        Records need to be accessed in the same order as they are stored.

Advantages of sequential access files:

·        File design is simple and easy.

·        Due to sequential storage nature, tapes can be used for storing data.

·        It is very efficient when all the records need to be processed during run time.

Disadvantages of sequential data files:

·        In order to search a single record, the entire file needs to be accessed.

·        The file is never up-to-date.

·        Overall processing is slow.

2. Random Access data file: In a random-access file, data are stored and accessed randomly.

Features:

·        Performs reading and writing operations randomly in any order.

·        Records can be accessed directly in any order.

Advantages of random-access file:

·        Any record can be accessed directly.

·        It has fast accessing speed.

·        Files can be kept up to date.

Disadvantages of random-access files:

·        It does not use all the locations.

·        Creates backup and security problem.

#File mode: The purpose of opening a data file is known as file mode.

Types of file mode:

(i)OUTPUT mode: To create new data file and write data in it. [store, create]

(ii)INPUT mode: To read/ retrieve contents from already existing data file. [display, view]

(iii)APPEND mode: To add records in the already existing data file. [add]

 

#EOF: This function is the abbreviation of the End Of File which is used for testing the end of a file. If the record pointer reaches at the end of a record it returns True(-1). If there are more records to be read from a data file, it returns False(0).

Syntax: EOF(file name)

Differences between WRITE# and PRINT# mode:

WRITE#

PRINT#

·        This statement stores values to a file as a separate data, so data in row can be read individually.

·        This statement writes values to a file as a single data, so data in row can’t be read individually.

·        This statement inserts commas between the data items and enclosed strings quotation.

·        This statement adds spaces between data item and does not encloses strings.

 

Differences between OUTPUT and APPEND mode:

OUTPUT mode

APPEND mode

·        OUTPUT mode creates a new sequential data file.

·        APPEND mode adds more records to an existing sequential data file.

·        If the file is already present, the previous file is deleted and a new file with the same name is created.

·        If the file is already present, the new records are added to the last of the previous records.

 

 


 

 

 


Sujit Prasad Kushwaha

A Dedicated Blogger Sharing Insights and Making a Difference.

Post a Comment

The comment section is your chance to make your mark. Don't hold back - add to the discussion and let your personality shine through!

Previous Post Next Post