SlideShare a Scribd company logo
File handling in qbasic
“
2
3
Concept
 The programs you have written till now require you
to re-enter data each time the program runs. This is
because the data stored in computer's temporary
memory disappears once the program stops running
or the computer is shut down.
 Information is saved in file, which is a collection of
data usually stored on a computer's disk.
 The smallest piece of meaningful information on a
file is called a data item.
4
5
TOPICS
1 3 5
6
4
2
File and its types
File organization
types
File management
statement and functions
File organization Process of using
file
Method of updating
a sequential file
 A computer is a computer resource for
recording data discretely in computer
storage device.
 Files are divided into two types in data
processing. They are:
 Program Files (which record and
maintain program listings)
 Data Files(which record and maintain
a collection of related information)
6
• File Organization refers to the relationship of the key
of the record to the physical location of that record in
the computer file.
• The objectives of computer based file organization :
• Ease of file creation and maintenance
• Efficient means of storing and retrieving the
information
• BASIC supports two types of file organizations. They
are:
 Random Access Files
 Sequential Access Files
7
 Random Access file is a file that can be accessed in any
order.
 Advantages of it are:
 Records can be immediately accessed for updation.
 Several file can be simultaneously updated during
transaction processing.
 Transaction need not be stored.
 Existing records can be amended or modified
 Disadvantages of it are:
 Less efficient use of storage space.
 Expensive hardware and software are required.
 High complexity in programming.
8
• Sequential access file is a file that must be accessed in
sequential order, starting at the beginning of the data block
and preceding in order until an end-of-data marker is
encountered of the required number of items has been read.
• Advantages
 Simple to understand
 Easy to maintain and organize
 Loading a record requires only the record key
 Easy to reconstruct the files
• Disadvantages
 Entire file must be processed, to get specific information
 Very low activity rate stored
 Transaction must be stored and placed in sequence prior to
processing
 Impossible to handle random enquiries 9
Modes of
operations of
sequential access
files
 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
create a new file. If 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 a specific reason to create new. 10
11
12
File handling in qbasic
14
COMPETITOR MATRIX
LOW
VALUE
1
HIGH
VALUE
1
LOW VALUE 2
HIGH VALUE 2
Our
company
Competitor
Competit
or
Competit
or
Competitor
Competit
or
Comp
etitor
Function Name of Command/ function Syntax
Renaming a Disk file NAME command NAME old filename AS new
filename
Deleting a name KILL command KILL filespec
Displaying Filenames FILES command FILES [filespec]
Creating new directory MKDIR command MKDIR pathname
Changing the default directory CHDIR command CHDIR pathname
Removing a directory RMDIR command RMDIR pathname
Reading a string of n characters INPUT$ function INPUT$(n,[,[#}filenum])
Reading data from a file INPUT# statement INPUT # filenum, variable list
Detecting the end of a file EOF function EOF (filenum)
Reading an entire line from a file LINE INPUT# LINE INPUT#filenum,string
15
Operation for updation of file
Modification of Existing records
To modify a sequential data file, entire
file is copied into a new data file with the
required corrections and then the new
data file is written back into the main
data file
Inserting New Records
Insertion means adding records to a file. At
times, new transactions may result in new
records which may not be present in the main
data file. A data file is opened in the append
mode("A") to add any new data at the end of the
data file. The data can also be added in between
the existing data by copying all the data file with
the additions required to a temporary data file
Deletion of Records
Deleting involves removing permanently
from a file. The records which will lose
their relevance over a period of time can
Searching a record
Searching means locating the desired
records in a file. In the case of sequential
file, records are stored sequentially. So
the search is also sequential , records are
searched one after the other.
Notes
 The INPUT # statement is used to read data items from a sequential
file and assign them to program variables.
 The EOF function is used to indicate the end of a sequential file.
 The LINE INPUT# statement is used to read an entire line without
delimiters from a sequence file into string variable.
 The NAME command is used to change the name of a name of a disk
file.
 The KILL command is used to delete a file from a disk
 The FILES command is used to display the names of the files on a
disk
 The MKDIR command is used to create a new directory on the
specified disk
 The CHDIR command is used to change the default directory on the
specified drive.
 The RMDIR command is used to remove a directory from the
specified disk.
 The INPUT$ function is used to read a string of n characters from
the file.
16
17
Updating a File
Updation Process
18
19
Temporary data file
on storage media Read and Overwrite
Main data file on
storage media
20
Steps to delete a
sequential access
data files
a. Open the main data file in the input mode("I") to
read data
b. Open a new temporary data file in output mode("O")
to write a data
c. Read data from the main data file and display to the
user
d. If you want to delete any data then donot write to the
temporary data file else write it in the temporary data
file.
e. Repeat steps c and d until all the data is written into
the temporary file
f. Close both the files
g. Delete main data file from the backing storage
h. Finally, rename temporary data file as main data file
21
Steps to insert
new records
between the
existing data
◦ Open the main data file in the input mode("I") to read
data
◦ Open a new temporary file in the output ("O") mode to
write data
◦ Read data from the main data file and write to the
temporary data file until the place where new data is to be
added is reached
◦ Get new data and write to the temporary data file
◦ Read rest of the main data file and write to the temporary
data file
◦ Close both the files
◦ Delete main data file from the storage device
◦ Finally, rename temporary data file as main data file
22
Steps to search
records
a. Open the main data file in the input mode("I") to read
data
b. Initialize the variable Flag by 0
c. Ask the user to input name to be searched
d. Read the data from the data file
e. Compare the input name with the name in data file
f. Is the name matching?
Yes: {Display the record
No: Goto step g}
g. Is EOF reached?
Yes: {Goto step h
No: Read the next record}
h. If Flag=0 the display "Record doesnot exist"
i. Close the file 23
24
Ad

More Related Content

What's hot (20)

Chapter 13 file systems
Chapter 13   file systemsChapter 13   file systems
Chapter 13 file systems
Alvin Chin
 
Data Structures & Algorithm design using C
Data Structures & Algorithm design using C Data Structures & Algorithm design using C
Data Structures & Algorithm design using C
Emertxe Information Technologies Pvt Ltd
 
File structures
File structuresFile structures
File structures
Shyam Kumar
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
bhawna kol
 
The cpu cycle
The cpu cycleThe cpu cycle
The cpu cycle
jndatirwa
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
prabhu rajendran
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
Mayank Bhatt
 
Data structures
Data structuresData structures
Data structures
Manaswi Sharma
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
Kumar Pritam
 
Files
FilesFiles
Files
kirtidhamija16
 
Basic dos-commands
Basic dos-commandsBasic dos-commands
Basic dos-commands
parag dhok
 
how to install window step by step
how to install window step by stephow to install window step by step
how to install window step by step
ahmreenmalik
 
operating system structure
operating system structureoperating system structure
operating system structure
Waseem Ud Din Farooqui
 
File based approach
File based approachFile based approach
File based approach
PreethaAS
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
Education Front
 
Exception Handling in VB.Net
Exception Handling in VB.NetException Handling in VB.Net
Exception Handling in VB.Net
rishisingh190
 
Unix Programming Lab
Unix Programming LabUnix Programming Lab
Unix Programming Lab
Neil Mathew
 
Auxiliary memory
Auxiliary memoryAuxiliary memory
Auxiliary memory
YuvrajVyas2
 
Unit 4 memory system
Unit 4   memory systemUnit 4   memory system
Unit 4 memory system
chidabdu
 
Central processing unit
Central processing unitCentral processing unit
Central processing unit
Kamal Acharya
 

Similar to File handling in qbasic (20)

Handling computer files
Handling computer filesHandling computer files
Handling computer files
Samuel Igbanogu
 
File Management System in Shell Script.pptx
File Management System in Shell Script.pptxFile Management System in Shell Script.pptx
File Management System in Shell Script.pptx
Green University of Bangladesh
 
File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 
File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 
Comp practical
Comp practicalComp practical
Comp practical
Kritika Sharma
 
INput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxINput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptx
AssadLeo1
 
File management
File managementFile management
File management
sumathiv9
 
File Handlingb in java. A brief presentation on file handling
File Handlingb in java. A brief presentation on file handlingFile Handlingb in java. A brief presentation on file handling
File Handlingb in java. A brief presentation on file handling
abdulsamadbrohi461
 
File Systems
File SystemsFile Systems
File Systems
Shipra Swati
 
Files and Directories in PHP
Files and Directories in PHPFiles and Directories in PHP
Files and Directories in PHP
Nicole Ryan
 
9780538745840 ppt ch05
9780538745840 ppt ch059780538745840 ppt ch05
9780538745840 ppt ch05
Terry Yoast
 
DFSNov1.pptx
DFSNov1.pptxDFSNov1.pptx
DFSNov1.pptx
EngrNabidRayhanKhale
 
File Management – File Concept, access methods, File types and File Operation
File Management – File Concept, access methods,  File types and File OperationFile Management – File Concept, access methods,  File types and File Operation
File Management – File Concept, access methods, File types and File Operation
Dhrumil Panchal
 
FILE MANAGEMENT.pptx
FILE MANAGEMENT.pptxFILE MANAGEMENT.pptx
FILE MANAGEMENT.pptx
jayashri kolekar
 
(file systems)12312321321321312312312.pptx
(file systems)12312321321321312312312.pptx(file systems)12312321321321312312312.pptx
(file systems)12312321321321312312312.pptx
ronniemayang
 
WINDOWS 10
WINDOWS 10WINDOWS 10
WINDOWS 10
lurdhu agnes
 
Sql server lesson3
Sql server lesson3Sql server lesson3
Sql server lesson3
Ala Qunaibi
 
Unit ivos - file systems
Unit ivos - file systemsUnit ivos - file systems
Unit ivos - file systems
donny101
 
Unit 6 OSY.pptx aaaaaaaaaaaaaaaaaaaaaaaa
Unit 6 OSY.pptx aaaaaaaaaaaaaaaaaaaaaaaaUnit 6 OSY.pptx aaaaaaaaaaaaaaaaaaaaaaaa
Unit 6 OSY.pptx aaaaaaaaaaaaaaaaaaaaaaaa
harshlad847
 
FIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptxFIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptx
Ashwini Raut
 
INput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxINput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptx
AssadLeo1
 
File management
File managementFile management
File management
sumathiv9
 
File Handlingb in java. A brief presentation on file handling
File Handlingb in java. A brief presentation on file handlingFile Handlingb in java. A brief presentation on file handling
File Handlingb in java. A brief presentation on file handling
abdulsamadbrohi461
 
Files and Directories in PHP
Files and Directories in PHPFiles and Directories in PHP
Files and Directories in PHP
Nicole Ryan
 
9780538745840 ppt ch05
9780538745840 ppt ch059780538745840 ppt ch05
9780538745840 ppt ch05
Terry Yoast
 
File Management – File Concept, access methods, File types and File Operation
File Management – File Concept, access methods,  File types and File OperationFile Management – File Concept, access methods,  File types and File Operation
File Management – File Concept, access methods, File types and File Operation
Dhrumil Panchal
 
(file systems)12312321321321312312312.pptx
(file systems)12312321321321312312312.pptx(file systems)12312321321321312312312.pptx
(file systems)12312321321321312312312.pptx
ronniemayang
 
Sql server lesson3
Sql server lesson3Sql server lesson3
Sql server lesson3
Ala Qunaibi
 
Unit ivos - file systems
Unit ivos - file systemsUnit ivos - file systems
Unit ivos - file systems
donny101
 
Unit 6 OSY.pptx aaaaaaaaaaaaaaaaaaaaaaaa
Unit 6 OSY.pptx aaaaaaaaaaaaaaaaaaaaaaaaUnit 6 OSY.pptx aaaaaaaaaaaaaaaaaaaaaaaa
Unit 6 OSY.pptx aaaaaaaaaaaaaaaaaaaaaaaa
harshlad847
 
FIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptxFIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptx
Ashwini Raut
 
Ad

Recently uploaded (20)

Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
Sugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptxSugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptx
Dr. Renu Jangid
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
National Information Standards Organization (NISO)
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
Sugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptxSugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptx
Dr. Renu Jangid
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
Ad

File handling in qbasic

  • 3. 3
  • 4. Concept  The programs you have written till now require you to re-enter data each time the program runs. This is because the data stored in computer's temporary memory disappears once the program stops running or the computer is shut down.  Information is saved in file, which is a collection of data usually stored on a computer's disk.  The smallest piece of meaningful information on a file is called a data item. 4
  • 5. 5 TOPICS 1 3 5 6 4 2 File and its types File organization types File management statement and functions File organization Process of using file Method of updating a sequential file
  • 6.  A computer is a computer resource for recording data discretely in computer storage device.  Files are divided into two types in data processing. They are:  Program Files (which record and maintain program listings)  Data Files(which record and maintain a collection of related information) 6
  • 7. • File Organization refers to the relationship of the key of the record to the physical location of that record in the computer file. • The objectives of computer based file organization : • Ease of file creation and maintenance • Efficient means of storing and retrieving the information • BASIC supports two types of file organizations. They are:  Random Access Files  Sequential Access Files 7
  • 8.  Random Access file is a file that can be accessed in any order.  Advantages of it are:  Records can be immediately accessed for updation.  Several file can be simultaneously updated during transaction processing.  Transaction need not be stored.  Existing records can be amended or modified  Disadvantages of it are:  Less efficient use of storage space.  Expensive hardware and software are required.  High complexity in programming. 8
  • 9. • Sequential access file is a file that must be accessed in sequential order, starting at the beginning of the data block and preceding in order until an end-of-data marker is encountered of the required number of items has been read. • Advantages  Simple to understand  Easy to maintain and organize  Loading a record requires only the record key  Easy to reconstruct the files • Disadvantages  Entire file must be processed, to get specific information  Very low activity rate stored  Transaction must be stored and placed in sequence prior to processing  Impossible to handle random enquiries 9
  • 10. Modes of operations of sequential access files  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 create a new file. If 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 a specific reason to create new. 10
  • 11. 11
  • 12. 12
  • 14. 14 COMPETITOR MATRIX LOW VALUE 1 HIGH VALUE 1 LOW VALUE 2 HIGH VALUE 2 Our company Competitor Competit or Competit or Competitor Competit or Comp etitor Function Name of Command/ function Syntax Renaming a Disk file NAME command NAME old filename AS new filename Deleting a name KILL command KILL filespec Displaying Filenames FILES command FILES [filespec] Creating new directory MKDIR command MKDIR pathname Changing the default directory CHDIR command CHDIR pathname Removing a directory RMDIR command RMDIR pathname Reading a string of n characters INPUT$ function INPUT$(n,[,[#}filenum]) Reading data from a file INPUT# statement INPUT # filenum, variable list Detecting the end of a file EOF function EOF (filenum) Reading an entire line from a file LINE INPUT# LINE INPUT#filenum,string
  • 15. 15 Operation for updation of file Modification of Existing records To modify a sequential data file, entire file is copied into a new data file with the required corrections and then the new data file is written back into the main data file Inserting New Records Insertion means adding records to a file. At times, new transactions may result in new records which may not be present in the main data file. A data file is opened in the append mode("A") to add any new data at the end of the data file. The data can also be added in between the existing data by copying all the data file with the additions required to a temporary data file Deletion of Records Deleting involves removing permanently from a file. The records which will lose their relevance over a period of time can Searching a record Searching means locating the desired records in a file. In the case of sequential file, records are stored sequentially. So the search is also sequential , records are searched one after the other.
  • 16. Notes  The INPUT # statement is used to read data items from a sequential file and assign them to program variables.  The EOF function is used to indicate the end of a sequential file.  The LINE INPUT# statement is used to read an entire line without delimiters from a sequence file into string variable.  The NAME command is used to change the name of a name of a disk file.  The KILL command is used to delete a file from a disk  The FILES command is used to display the names of the files on a disk  The MKDIR command is used to create a new directory on the specified disk  The CHDIR command is used to change the default directory on the specified drive.  The RMDIR command is used to remove a directory from the specified disk.  The INPUT$ function is used to read a string of n characters from the file. 16
  • 18. 18
  • 19. 19 Temporary data file on storage media Read and Overwrite Main data file on storage media
  • 20. 20
  • 21. Steps to delete a sequential access data files a. Open the main data file in the input mode("I") to read data b. Open a new temporary data file in output mode("O") to write a data c. Read data from the main data file and display to the user d. If you want to delete any data then donot write to the temporary data file else write it in the temporary data file. e. Repeat steps c and d until all the data is written into the temporary file f. Close both the files g. Delete main data file from the backing storage h. Finally, rename temporary data file as main data file 21
  • 22. Steps to insert new records between the existing data ◦ Open the main data file in the input mode("I") to read data ◦ Open a new temporary file in the output ("O") mode to write data ◦ Read data from the main data file and write to the temporary data file until the place where new data is to be added is reached ◦ Get new data and write to the temporary data file ◦ Read rest of the main data file and write to the temporary data file ◦ Close both the files ◦ Delete main data file from the storage device ◦ Finally, rename temporary data file as main data file 22
  • 23. Steps to search records a. Open the main data file in the input mode("I") to read data b. Initialize the variable Flag by 0 c. Ask the user to input name to be searched d. Read the data from the data file e. Compare the input name with the name in data file f. Is the name matching? Yes: {Display the record No: Goto step g} g. Is EOF reached? Yes: {Goto step h No: Read the next record} h. If Flag=0 the display "Record doesnot exist" i. Close the file 23
  • 24. 24