Revision 10

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

File Handling in QBASIC

Chapter-

1. File Handline:
● Process of creating data file.

● Write data to the data file and

● Read data from the specified data file.


2. Basic Operations on data file:
i. OUTPUT MODE:
a. Creating a new sequential data file and store data or
records in that sequential data file.
ii. APPEND MODE:
a. Adding more data or records in the existing
sequential data file.
b. We cannot read or display the data or records that is
stored in existing data file.
iii. INPUT MODE:
Differents operations are performed in this mode i.e
a. Read data or records form the existing data file.
b. Delete the specific data or record from the existing
data file.
c. Search the particular data or record in the existing
data file.
d. Count the data or records that are available inside
the existing data file.
e. Copy the data or records from the existing data file
and paste it to the newly created data file. In this
case after copy task is performed the old existing
file is deleted by using kill command and the newly
created data file is renamed as old existing file
name by using Name command in the program.
3. Keywords used in File Handling:
a. OPEN
b. CLS
c. INPUT
d. PRINT
e. CLOSE
f. END
g. PRINT# / WRITE#
h. INPUT#
a. OPEN: [Used in All three modes]
● Specially used to open file to perform writing data, reading data
from the data file etc.
● Syntax:
OPEN “file name” FOR MODE AS # file number
or
OPEN MODE #file number, “File name”
i.e.
OPEN “O”, #1, “File name”
Statements Used in Output and Append Modes
a. WRITE # statement:
● used to write data to a sequential data file.

● it writes (store) the values stored in the variables in the file


having file number.
● Syntax:
WRITE #file number, expressionlist
or
PRINT #file number, expressionlist
b. CLOSE statement:
● It closes all the files opened in the entire program.

● It closes the file having file number.

● It can close more than one file at a time.

● Syntax:
CLOSE #file number, #file number, ……..
c. INPUT Statement:
● Used to receive or take data from user in the program.

Statements used in INPUT Mode:


a. INPUT # statement:
● To read data or records from an existing data file, we use this
IINPUT # statement.
● Syntax:
INPUT #file number, variable list
b. PRINT Statement:
● Used to display the result or messages in the output console.
Note: The number of variables and their types must be matching to the fields of
data stored in the data file.

4. EOF (check end of file) Function:


● Function that Tests for the end of a file.

● It returns TRUE if the end of the file has been reached and returns FALSE
when the end of the file has not been reached.
● Syntax: 
EOF ( file number )

● Eg:
EOF ( 1 )
5. Methods of Questions:
1. For…………next Loop:
● if the questions tells or says to store fixed number of datas or
records in the sequential data file, we use this loop.
2. GOTO……TOP:
● IF the questions tells or says to store the records or datas in the
data file according to the user’s choice or need or more records
without any fixed number than we use this GOTO…TOP
statement.
Note: These above methods are applicable for OUTPUT MODE and APPEND
MODE only but not for INPUT MODE.

IN Case of INPUT MODE:


● USE EOF() function

● WHILE…..WEND Loop.

● IF statement
To read or displays or perform other operations like count, delete, search,
copy etc the above mentioned points are used in the program.

You might also like