Filter Courses

File Handling in QBASIC

Published by: BhumiRaj Timalsina

Published Date: 10 Jan 2022

File Handling in QBASIC in grade 10

Introduction

Data are used in all the programs for retrieving information. In QBASIC you can store data in a separate file called a data file. Hence there are two types of files in data processing. They are:Open  file, process file.

  • Program file :A program file contains a set of instructions that are needed for data processing. A program file has BAS extention.
  • Date file : A data file contains only data that are required during data processing. In a data file related of a person or any thing are stored in a row known as a record.

Types of File Handling

  • Sequential Data File : It is a file that should be accessed in a sequential manner starting at the beginning of the data block and process ending in order until and end of data.
  • Random Data File: It is a file which a key is used to point its appropriate record stored on a disk.

Some useful commands with their function and syntax are given below:

Files: This command is used to display all the files of current drive. Syntax: Files [File specification]

Shell: This command is used to go to DOS prompt temporarily.

NAME: This command is used to change the old file into new file. Syntax: Name " old file name" AS "New file name"

Kill: This command is used to remove the file from the disk. Syntax: Kill [ File Specification ]

MKDIR: This command is used to create a directory in a specific disk Syntax: MKDIR "path"

CHDIR: This command is used to change the directory. Syntax: CHDIR " path"

RMDIR: This command is used to remove the specific directory. Syntax: RMDIR "path"

System: This command is used to close the Q-BASIC program.

OPEN: This statement is used to open the file.

WRITE#: This statement is used to place the data into data file.

NPUT#: This statement is used to read each data and stores to corresponding variable.

LINE INPUT#: This statement reads entire line having maximum 255 characters and stores to a single string variable.

EOF ( ) : This statement is used to end a file. Syntax: EOF ( File number)

Modes of operations of sequential access data file

You need to open a sequential access data file in order to use it. A sequential data file can be opened in one of three modes.

Types of Mode:

  • OUTPUT mode : A file is opened in output mode to write data to the file. When a file is opened in output mode BASIC always creates a new file. If a file with the name already exists then it will overwrite without warning.
  • INPUT mode : A file is opened in input mode to read data from the file. The file must exist to open it in input mode otherwise error message "file not found" is displayed.
  • APPEND mode : A file is opened in append mode to add data to an existing file. New data are added to the end of existing file. It is recommended mode for writing data to a file unless there is specific reason to create new.
Menu