SlideShare uma empresa Scribd logo
1 de 36
Presentation
      on
File Handling
Contents
   Definition Of File
   Types Of Files
   Operations on File
    Opening A File
    Closing A File
    Writing Data To A File
    Reading Data From A File
    Detecting The End of File
    Storing A File
    Demo Application
Definition Of File
   A File is a collection of data stored on a
    computer’s disk.
   Information can be saved to files and later
    reused.
Types Of Files
   There are three types of files.
1)   Sequential Access Files
2)   Random Access Files
3)   Binary Files
Sequential Access File
   A sequential access file is a stream of data that

    must be read from its beginning to its end.

   To read a record that is stored in the middle or at

    the end of sequential access file an application

    must read all the records in the file before it.
Random Access File
   In Random access file Records must be identical

    in length and may be accessed in any order.

   An application may immediately jump to any

    record in a random access file without first

    reading the preceding records.
Binary File
   In binary file data is stored in binary form not in

    plain text.

   The records in binary files may vary in length.

   Binary files are usually smaller than text files but

    user cannot view their contents with text editor.
Binary File
   In binary file data is stored in binary form not in

    plain text.

   The records in binary files may vary in length.

   Binary files are usually smaller than text files but

    user cannot view their contents with text editor.
Operations on File
File Open Mode
Input           Used with sequential acess file.
                Data will read from the files.
Output          Used with sequential access files .
                Data will be written to the file.
Append          Used with a sequential access file.
                Data will be written to the end of
                the file.
Random          This file is opened for random
                access . If the file does not
                exist,it is created.
Binary          The file is opened in binary mode.
                If the file does not exist , it is
                created .
Opening A File
   Open statement is used to open a file.



Syntax :


Open*filename*for mode as # filenumber [len=recordlength]
Contd..
   When a sequential file is opened , visual basic

    creates a file buffer.

   A file buffer is a small holding section of memory

    that data is first written to.
Closing A File
   Close statement is used to close a file.

         Syntax :


             Close [filenumberlist]



• In syntax, Filenumberlsit is one or more file
  numbers separated by commas.
Contd..
   The # symbol must appear with each file number.

   Example close #1,#2

   If user don’t specify any file number , visual basic

    closes all the files the applications has opened.
Writing data to a File
   Data may be written to a file that is opened in

    either output or append mode.

   The write statement is used to write a data to the

    file.
             Syntax


              Write # filenumber, [itemlist]
Reading data from a file
   Data may be read from a file that already exist

    and is opened in input mode.

   The input statement is used to read data from a

    file.
            Syntax

            Input # filenumber, itemlist
Opening a file in append mode
   When a file is opened in append mode data is

    written to the end of the file.

   If the file is already exist its contents are not

    erased.

   If the file does not exist it is created.
Contd..
.
      Syntax

    Open filename for append as #1
Detecting the end of the file
   The EOF function detects when the end of file has been

    reached.

                Syntax


               EOF(file number)



     The function proves true if the end of file has been

    reached or false if the end of file has not been reached.
Application on file handling
How to apply picture on command
             button

   Select the command button.
   Draw it and then go to properties window.
   Change the style property to 1-graphical.
   Select the picture option.
   Select the picture user want to apply.
How to draw a shape
•Select the shape option from the toolbox.
•Then go to shape properties and select any
option.




                                        Shape
                                        option
Coding Of this Form
   Private Sub cmdappend_Click()

   Unload Me

   frmappend.Show

   End Sub



   Private Sub cmdclose_Click()

   Unload Me

   End

   End Sub
Contd….
   Private Sub cmdcreate_Click()

   Unload Me

   frmcreate.Show

   End Sub

   Private Sub cmdread_Click()

   Unload Me

   frmread.Show

   End Sub

   Private Sub cmdwrite_Click()

   Unload Me

   frmwrite.Show

   End Sub
Contd….
   Dim fname As String

   Dim productname As String

   Dim companyname As String

   Dim price As Integer

   Dim intcount As Integer

   Private Sub cmdclose_Click()

   Unload Me

   End

   End Sub
Contd….
   Private Sub cmdcreate_Click()

   fname = InputBox("Enter the File Name")

   Open fname For Output As #1

   For intcount = 1 To 4

   MsgBox " Enter the product details " & FormatNumber(intcount, 0)

   productname = InputBox("Enter the Product name")

   companyname = InputBox("Enter the Company name")

   price = Val(InputBox("Enter the Price"))

   Write #1, productname, companyname, price

   Next intcount

   Close #1

   End Sub
Control Array
   A control array is a group of controls all of the
    same type.
   The control array has a name but the individual
    controls in the array donot.
   To refer to a member of a control array, the
    syntax is:
   ControlName(Index)[.Property]
How to create a control array
   Select (command button,text box ,label etc).

   Then draw it.

   Then copy it and paste it.

   It will ask do you want to create a control array

    then click yes.
Coding
   Private Sub cmdappend_Click()
   Open "d:aman.txt" For Append As #1
   productname = "laptop"
   companyname = "samsung"
   price = 33000
   Write #1, productname, companyname, price
   Close #1
   End Sub

 Private Sub cmdclose_Click()
 Unload Me
 End
 End Sub
Coding
 Private Sub cmdclose_Click()
 Unload Me
 End
 End Sub


   Private Sub cmdwrite_Click()
   Open "d:aman.txt" For Output As #1
   productname = "laptop"
   companyname = "samsung"
   price = 33000
   Write #1, productname, companyname, price
   Close #1
   End Sub
File Handling: Opening, Writing, Reading and Closing Files in Visual Basic

Mais conteúdo relacionado

Mais procurados

Objects and classes in Visual Basic
Objects and classes in Visual BasicObjects and classes in Visual Basic
Objects and classes in Visual BasicSangeetha Sg
 
File handling in vb.net
File handling in vb.netFile handling in vb.net
File handling in vb.netEverywhere
 
Byte stream classes.49
Byte stream classes.49Byte stream classes.49
Byte stream classes.49myrajendra
 
File Management in C
File Management in CFile Management in C
File Management in CPaurav Shah
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and UnionsDhrumil Patel
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ pptKumar
 
Visual Basic menu
Visual Basic menuVisual Basic menu
Visual Basic menukuldeep94
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CMahendra Yadav
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overridingRajab Ali
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++Muhammad Waqas
 
Common language runtime clr
Common language runtime clrCommon language runtime clr
Common language runtime clrSanSan149
 
File Handling Python
File Handling PythonFile Handling Python
File Handling PythonAkhil Kaushik
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 

Mais procurados (20)

Objects and classes in Visual Basic
Objects and classes in Visual BasicObjects and classes in Visual Basic
Objects and classes in Visual Basic
 
File handling in vb.net
File handling in vb.netFile handling in vb.net
File handling in vb.net
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Byte stream classes.49
Byte stream classes.49Byte stream classes.49
Byte stream classes.49
 
File Management in C
File Management in CFile Management in C
File Management in C
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Visual Basic menu
Visual Basic menuVisual Basic menu
Visual Basic menu
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in C
 
Built in function
Built in functionBuilt in function
Built in function
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
 
C functions
C functionsC functions
C functions
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Common language runtime clr
Common language runtime clrCommon language runtime clr
Common language runtime clr
 
Constants in java
Constants in javaConstants in java
Constants in java
 
Functions in c
Functions in cFunctions in c
Functions in c
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 

Destaque

Destaque (20)

File handling
File handlingFile handling
File handling
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 
Creating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDBCreating, Updating and Deleting Document in MongoDB
Creating, Updating and Deleting Document in MongoDB
 
Data file handling
Data file handlingData file handling
Data file handling
 
Chap 1 c++
Chap 1 c++Chap 1 c++
Chap 1 c++
 
Files and file objects (in Python)
Files and file objects (in Python)Files and file objects (in Python)
Files and file objects (in Python)
 
Menu vb
Menu vbMenu vb
Menu vb
 
Symmetric multiprocessing (smp)
Symmetric multiprocessing (smp)Symmetric multiprocessing (smp)
Symmetric multiprocessing (smp)
 
File handling
File handlingFile handling
File handling
 
Standard Algorithms
Standard AlgorithmsStandard Algorithms
Standard Algorithms
 
Vb net xp_10
Vb net xp_10Vb net xp_10
Vb net xp_10
 
Data file handling in c++
Data file handling in c++Data file handling in c++
Data file handling in c++
 
Vb.net session 01
Vb.net session 01Vb.net session 01
Vb.net session 01
 
Real time operating system
Real time operating systemReal time operating system
Real time operating system
 
Operating system introducton and tyes
Operating system introducton and tyesOperating system introducton and tyes
Operating system introducton and tyes
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
 
file handling c++
file handling c++file handling c++
file handling c++
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 

Semelhante a File Handling: Opening, Writing, Reading and Closing Files in Visual Basic

Semelhante a File Handling: Opening, Writing, Reading and Closing Files in Visual Basic (20)

Filepointers1 1215104829397318-9
Filepointers1 1215104829397318-9Filepointers1 1215104829397318-9
Filepointers1 1215104829397318-9
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
Filehandlinging cp2
Filehandlinging cp2Filehandlinging cp2
Filehandlinging cp2
 
Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))
 
Data file handling
Data file handlingData file handling
Data file handling
 
Chapter10
Chapter10Chapter10
Chapter10
 
ExplanationThe files into which we are writing the date area called.pdf
ExplanationThe files into which we are writing the date area called.pdfExplanationThe files into which we are writing the date area called.pdf
ExplanationThe files into which we are writing the date area called.pdf
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
 
File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
File Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingFile Management and manipulation in C++ Programming
File Management and manipulation in C++ Programming
 
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSFILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
 
3.1 file input and output
3.1   file input and output3.1   file input and output
3.1 file input and output
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
 
File Handling in c++
File Handling in c++File Handling in c++
File Handling in c++
 
Python-files
Python-filesPython-files
Python-files
 
file_c.pdf
file_c.pdffile_c.pdf
file_c.pdf
 

Mais de Amandeep Kaur

Video/ Graphics cards
Video/ Graphics  cardsVideo/ Graphics  cards
Video/ Graphics cardsAmandeep Kaur
 
Menu pop up menu mdi form and playing audio in vb
Menu pop up menu mdi form and playing audio in vbMenu pop up menu mdi form and playing audio in vb
Menu pop up menu mdi form and playing audio in vbAmandeep Kaur
 
Image contro, and format functions in vb
Image contro, and format functions in vbImage contro, and format functions in vb
Image contro, and format functions in vbAmandeep Kaur
 
Data base connectivity and flex grid in vb
Data base connectivity and flex grid in vbData base connectivity and flex grid in vb
Data base connectivity and flex grid in vbAmandeep Kaur
 
Toolbar, statusbar, coolbar in vb
Toolbar, statusbar, coolbar in vbToolbar, statusbar, coolbar in vb
Toolbar, statusbar, coolbar in vbAmandeep Kaur
 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphicsAmandeep Kaur
 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphicsAmandeep Kaur
 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphicsAmandeep Kaur
 
Report on browser war
Report on browser warReport on browser war
Report on browser warAmandeep Kaur
 
Report of internet connections
Report of internet connectionsReport of internet connections
Report of internet connectionsAmandeep Kaur
 
How to configure dns server(2)
How to configure dns server(2)How to configure dns server(2)
How to configure dns server(2)Amandeep Kaur
 

Mais de Amandeep Kaur (20)

Video/ Graphics cards
Video/ Graphics  cardsVideo/ Graphics  cards
Video/ Graphics cards
 
Menu pop up menu mdi form and playing audio in vb
Menu pop up menu mdi form and playing audio in vbMenu pop up menu mdi form and playing audio in vb
Menu pop up menu mdi form and playing audio in vb
 
Active x control
Active x controlActive x control
Active x control
 
Image contro, and format functions in vb
Image contro, and format functions in vbImage contro, and format functions in vb
Image contro, and format functions in vb
 
Data base connectivity and flex grid in vb
Data base connectivity and flex grid in vbData base connectivity and flex grid in vb
Data base connectivity and flex grid in vb
 
Toolbar, statusbar, coolbar in vb
Toolbar, statusbar, coolbar in vbToolbar, statusbar, coolbar in vb
Toolbar, statusbar, coolbar in vb
 
Richtextbox
RichtextboxRichtextbox
Richtextbox
 
Treeview listview
Treeview listviewTreeview listview
Treeview listview
 
Progress bar
Progress barProgress bar
Progress bar
 
Socket
SocketSocket
Socket
 
Ppt of socket
Ppt of socketPpt of socket
Ppt of socket
 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphics
 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphics
 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphics
 
Internet
InternetInternet
Internet
 
Internet working
Internet workingInternet working
Internet working
 
Report on browser war
Report on browser warReport on browser war
Report on browser war
 
Report of internet connections
Report of internet connectionsReport of internet connections
Report of internet connections
 
Report on intranet
Report on intranetReport on intranet
Report on intranet
 
How to configure dns server(2)
How to configure dns server(2)How to configure dns server(2)
How to configure dns server(2)
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 

Último (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 

File Handling: Opening, Writing, Reading and Closing Files in Visual Basic

  • 1. Presentation on File Handling
  • 2. Contents  Definition Of File  Types Of Files  Operations on File  Opening A File  Closing A File  Writing Data To A File  Reading Data From A File  Detecting The End of File  Storing A File  Demo Application
  • 3. Definition Of File  A File is a collection of data stored on a computer’s disk.  Information can be saved to files and later reused.
  • 4. Types Of Files  There are three types of files. 1) Sequential Access Files 2) Random Access Files 3) Binary Files
  • 5. Sequential Access File  A sequential access file is a stream of data that must be read from its beginning to its end.  To read a record that is stored in the middle or at the end of sequential access file an application must read all the records in the file before it.
  • 6. Random Access File  In Random access file Records must be identical in length and may be accessed in any order.  An application may immediately jump to any record in a random access file without first reading the preceding records.
  • 7. Binary File  In binary file data is stored in binary form not in plain text.  The records in binary files may vary in length.  Binary files are usually smaller than text files but user cannot view their contents with text editor.
  • 8. Binary File  In binary file data is stored in binary form not in plain text.  The records in binary files may vary in length.  Binary files are usually smaller than text files but user cannot view their contents with text editor.
  • 10. File Open Mode Input Used with sequential acess file. Data will read from the files. Output Used with sequential access files . Data will be written to the file. Append Used with a sequential access file. Data will be written to the end of the file. Random This file is opened for random access . If the file does not exist,it is created. Binary The file is opened in binary mode. If the file does not exist , it is created .
  • 11. Opening A File  Open statement is used to open a file. Syntax : Open*filename*for mode as # filenumber [len=recordlength]
  • 12. Contd..  When a sequential file is opened , visual basic creates a file buffer.  A file buffer is a small holding section of memory that data is first written to.
  • 13. Closing A File  Close statement is used to close a file. Syntax : Close [filenumberlist] • In syntax, Filenumberlsit is one or more file numbers separated by commas.
  • 14. Contd..  The # symbol must appear with each file number.  Example close #1,#2  If user don’t specify any file number , visual basic closes all the files the applications has opened.
  • 15. Writing data to a File  Data may be written to a file that is opened in either output or append mode.  The write statement is used to write a data to the file. Syntax Write # filenumber, [itemlist]
  • 16. Reading data from a file  Data may be read from a file that already exist and is opened in input mode.  The input statement is used to read data from a file. Syntax Input # filenumber, itemlist
  • 17. Opening a file in append mode  When a file is opened in append mode data is written to the end of the file.  If the file is already exist its contents are not erased.  If the file does not exist it is created.
  • 18. Contd.. . Syntax Open filename for append as #1
  • 19. Detecting the end of the file  The EOF function detects when the end of file has been reached. Syntax EOF(file number) The function proves true if the end of file has been reached or false if the end of file has not been reached.
  • 21.
  • 22. How to apply picture on command button  Select the command button.  Draw it and then go to properties window.  Change the style property to 1-graphical.  Select the picture option.  Select the picture user want to apply.
  • 23. How to draw a shape •Select the shape option from the toolbox. •Then go to shape properties and select any option. Shape option
  • 24. Coding Of this Form  Private Sub cmdappend_Click()  Unload Me  frmappend.Show  End Sub  Private Sub cmdclose_Click()  Unload Me  End  End Sub
  • 25. Contd….  Private Sub cmdcreate_Click()  Unload Me  frmcreate.Show  End Sub  Private Sub cmdread_Click()  Unload Me  frmread.Show  End Sub  Private Sub cmdwrite_Click()  Unload Me  frmwrite.Show  End Sub
  • 26.
  • 27. Contd….  Dim fname As String  Dim productname As String  Dim companyname As String  Dim price As Integer  Dim intcount As Integer  Private Sub cmdclose_Click()  Unload Me  End  End Sub
  • 28. Contd….  Private Sub cmdcreate_Click()  fname = InputBox("Enter the File Name")  Open fname For Output As #1  For intcount = 1 To 4  MsgBox " Enter the product details " & FormatNumber(intcount, 0)  productname = InputBox("Enter the Product name")  companyname = InputBox("Enter the Company name")  price = Val(InputBox("Enter the Price"))  Write #1, productname, companyname, price  Next intcount  Close #1  End Sub
  • 29. Control Array  A control array is a group of controls all of the same type.  The control array has a name but the individual controls in the array donot.  To refer to a member of a control array, the syntax is:  ControlName(Index)[.Property]
  • 30. How to create a control array  Select (command button,text box ,label etc).  Then draw it.  Then copy it and paste it.  It will ask do you want to create a control array then click yes.
  • 31.
  • 32.
  • 33. Coding  Private Sub cmdappend_Click()  Open "d:aman.txt" For Append As #1  productname = "laptop"  companyname = "samsung"  price = 33000  Write #1, productname, companyname, price  Close #1  End Sub  Private Sub cmdclose_Click()  Unload Me  End  End Sub
  • 34.
  • 35. Coding  Private Sub cmdclose_Click()  Unload Me  End  End Sub  Private Sub cmdwrite_Click()  Open "d:aman.txt" For Output As #1  productname = "laptop"  companyname = "samsung"  price = 33000  Write #1, productname, companyname, price  Close #1  End Sub