SlideShare a Scribd company logo
1 of 8
Download to read offline
TYBSC (IT) Visual Basic


                                                  Chapter-10
                                                  Data Files



Q. 1. What is the difference between a Visual Basic project file and a data file?( 4 mrks )

              Visual Basic project file                                       Data File

Each of our VB project file requires multiple              Anything that we store on a hard disk is given
files for the forms , standard code modules,               its own unique name and is called a Data file.
and project modules.

In this, some situations we require large                  The file is made up of records one record for
quantities of data or information to be                    each entity in the file. Each record can be
processed.                                                 broken down further into fields



Q. 2 What occurs when open statement is executed ?( 4 rks )

       We can use open statement for both i.e. sequential and random access files. Open
statement reserves file handle, also called a channel for reading from and writing to a file. The
open statement associates number to the handle. A file handle is a unique path to file
associated with a number from the open statement. Open statement associates a number to
the handle after that we can use the file number to access the file. Similarly, we have to specify
the mode in which we want to open the file. These mode can be read , write or both.

Q. 3. List and explain the file modes for data files.(6 mrks )

       File modes for data files are as follows:

        i)         Append:

                            Opens a file for sequential output starting at the end of file.

        ii)        Input:

                            Opens a file for sequential input, we can read from the file.

        iii)       Output:

                            Opens a file for sequential output, starting from beginning of file.

        iv)        Random:

                            Open a file for random read and write access. This mode allows to read
                            and write to a file at any specified record boundaries.



                                                       1
TYBSC (IT) Visual Basic


Q. 4. What is the significance of file number?( 4 mrks )

         A file number is used to maintain the files. In the project suppose we have large number
of files , so instead of using the various file names we refer to the file numbers.

        Syntax is as follows:

                  Open “filename” # 1

        For ex.

                  Open “Abc.txt” # 1

                Above statement opens the file Abc.txt. It associates a file number one to abc.txt
To refer to this file we can use this file number.



Q. 5. Explain difference between the Output and Append modes.( 4 mrks )



                   Output Mode                                       Append mode

Opens a file for sequential output, starting        It opens a file for sequential output, starting at
from the beginning of the file.                     the end of the file.

 For Ex :                                           For Ex:
Private Sub Command_click()                         Private Sub Command_click()
filenum = FreeFile Open “C: output.txt”            filenum = FreeFile Open “C: output.txt”

For Output As filenum                               For Append As filenum
Print #filenum , text1.text                         Print #filenum , text1.text
Close filenum                                       Close filenum
End Sub                                             End Sub




Q. 6. What is the format for the statements to read and write sequential files?( 6 mrks )

        Sequential file contains data elements that are stored one after another in sequence.
When we read the data from the disk, it must be read in the same sequence in which it was
written. To read any particular element of data, all proceeding must first be read.

        As data elements are written on disk, string fields are enclosed in quotation marks and
fields and separated by, records are generally terminated a carriage written character.

                                                2
TYBSC (IT) Visual Basic


       Input statement is used to read the data from the a sequential file.

       Syntax is :

                 Input # intFileNumber , variable1 , variable2 ,…

                 Input statement requires file number and variables to hold the data.

       For ex.

                 Private Sub cmdRead_click()

                         Dim intV1, intV2, intV3, as Integer

                         Open “c:/seg.txt” for input as # 1

                         Input # 1 intV1, intV2, intV3

                         Close # 1

                         MsgBox “Seg.txt Contains “ &intV1, &intV2, &intV3

                 End Sub



        For writing purpose we use the write # statement to place data into a sequential data file.
Before the write # statements can be executed , the file must be opened in either output mode
or append mode. For append mode, the file pointer is placed at the end of file. If there are no
records, the beginning of end of file. In output mode, the pointer is placed at the beginning of the
file. Use output mode to create a new file ot write old data.

       Syntax is :

                 Write # file number , list of fields

       Ex.

                 Write # 1 , txtAmount.text , txtDescription.text , txtPrice.text

                 Write # 2 , strAccount



Q.7 . What function can be used to determine an available file number?( 4 mrks )

        When we open a file, we must assign a file number to each file. For a small project, with
one or two data files, most programmer‟s assign # 1 and # 2.But in larger project selecting a file
number can be a problem. If our code will be part of larger project with code from other
programmers and other libraries we must make same to avoid any conflicting file number.


                                                    3
TYBSC (IT) Visual Basic


       To solve this problem we can allow the system to assign the next available file number
use the FreeFile function to assign the next available file number to our file and we will never
have conflict.



       Ex. Dim intFileNum as Integer

       intFileNum = FreeFile

       „ Get next available file number

       Open “Abc.txt” for output as # intFileNum



Q. 8. When would an On Error statement be used?( 6 mrks )

       We must place an On Error statement at the beginning of the any procedure where error
might occur, such as before opening sequential file for input.

        An on error statement will trap the error and it will direct the execution control to the error
trap level. Actually , there are four different statements that we can use when error occurs.

        i.Resume Next:It tells VB that if an error occurs,the program should simply skip to the
next lineof the code and bypass the line where the error has occured.

               Example:

                       Private sub cmdDelete_Click( )

                       on Error Resume Next

                       Stop

                       Kill txtFile    'Kill statement delete the specified file in the textbox

                       if err.Number     then

                       MsgBox " such a file doesn't exit "

                       Endif

                       End Sub



        ii.Resume (Label Name ):This statement is used , if you want to transfer execution
control.To some different location or you just want to ignore the error

                       Example:

                                                   4
TYBSC (IT) Visual Basic


                               private sub cmdOpen_Click( )

                               OnError GoTo ErrorTrap

                               set db = OpenDatabase("C:emp.mdb")

                               Normal Exit:

                               Exit Sub

                               Error Trap:

                               Msgbox " Failed to open the file "

                               Resume NormalExit

                               End sub

           iii.Resume :When Error occurs and if you want to give the user a chance to fix the
error , In that caes above statement is used.

               Example:

                     If your tries to access a floppy without putting it intothe disk drive , you
application may ask you to insert it and then continue with the execution again.

               private sub cmdResume_Click( )

               On Error Go To ErrorTrap

               MsgBox" Length of the file is " & FileLen( txtFile )

               Normal Exit:

               Exit sub

               Error Trap:

               If err.Number then

               If MsgBox (" Floppy drive error try again ") = vbYes then

               Resume

               Endif

               End Sub

       iv.The errObject:Every time an error occurs vb creates an object, which contain erroe
information this error object can be used to retrive the information about the type of error , which
has occured the important properties of errorobject are as follows:


                                                  5
TYBSC (IT) Visual Basic


               property                     Description

               1.Number                     Identifies the specified error that occurs.

               2.Description                Take description of the error.

              3.Source                      A String identifying the name of the object that are
generated the error

Q.9. Explain the function and use of Err object.( 6 mrks )

        Every time an error occurs VB creates an object, which contains error information. This
Err object can be used to retrieve the information about the type of error which has occured.



       Properties of Err Object are as follows:



                          Property                                   Description

       Number                                        Indentifies specified error that occur.

       Description                                   Takes description of the error.

       Source                                        A string identifying name of the object that
                                                     has generated error.



       Methods of Err Object are as Follows:

                          Method                                     Description

       Clear                                         Clears any information contain in the error
                                                     object.

       Raise                                         This method can be used to test the error
                                                     handling code. We can use this method to
                                                     generate run time errors.



Q. 10 What are the difference between a random file and a sequential file? ( 6 mrks )



            Random Access File                               Sequential Access File



                                               6
TYBSC (IT) Visual Basic


Random Access file is made up of identical            Sequential Access files are accessed by line
size. Each record is made up of identical size.       by line for applications that manipulate text
                                                      files.

 Get and Put statements are used to access            Input, Write statements are used to access the
random access file.                                   sequential access file.

For ex.                                               For ex.
Private Sub Form_Load()                               Private Sub Command1_Click()
RecorLen = Len(product)                               fileNum= FreeFile                Open
FileNum = FreeFile                                    “C:output.txt” for Output As fileNum
Open “c:Product.dat” for Random as FileNum           Print# fileNum , text1.text
Len= RecordLen                                        Close fileNum
                                                      End Sub



Q. 11. What does updating a data file mean?( 4 mrks )

       A file update generally consists of routine to add records, update records, delete
records and browse through records. The procedures for these options might be selected from a
command button or a menu command.

       Each routine must display the fields from the file, so we will use one form and refer to it
as the data form. This form contains text boxes for each field of a record along with the
appropriate labels.

Q.12 Explain Get statement and put statement.( 4 mrks )

       This two statement are used to access Random Access Files.

                Get is used to read particular record from a file.Similary,Put is used to write a
particular record in a file.

       Syntax:

               Put # intFileNum , intRecordNum , variable

               Get # intFileNum , intRecordNum , variable

                      Both of the above use RecordNum , which indicates RecordNumber ,you
want to works with the variable can be of any datatype , it can be array or userdefine datatype.

       Example:

               Private sub cmdWrite_Click( )

               Dim Ctr As integer


                                                  7
TYBSC (IT) Visual Basic


       Open" C: ABC.txt " for Random As # 1Len=5

       for intCtr =1 to 5

       Put #1, intCtr , intCtr

       Next intCtr

       Close#1

       End Sub




                                            8

More Related Content

What's hot

What's hot (20)

File and directories in python
File and directories in pythonFile and directories in python
File and directories in python
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
 
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
 
Linux 系統程式--第一章 i/o 函式
Linux 系統程式--第一章 i/o 函式Linux 系統程式--第一章 i/o 函式
Linux 系統程式--第一章 i/o 函式
 
Filehandling
FilehandlingFilehandling
Filehandling
 
python file handling
python file handlingpython file handling
python file handling
 
File Pointers
File PointersFile Pointers
File Pointers
 
Filehandlinging cp2
Filehandlinging cp2Filehandlinging cp2
Filehandlinging cp2
 
Python-files
Python-filesPython-files
Python-files
 
17 files and streams
17 files and streams17 files and streams
17 files and streams
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Python - File operations & Data parsing
Python - File operations & Data parsingPython - File operations & Data parsing
Python - File operations & Data parsing
 
Data file handling in c++
Data file handling in c++Data file handling in c++
Data file handling in c++
 
File handling and Dictionaries in python
File handling and Dictionaries in pythonFile handling and Dictionaries in python
File handling and Dictionaries in python
 
Chapter 08 data file handling
Chapter 08 data file handlingChapter 08 data file handling
Chapter 08 data file handling
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
 

Viewers also liked

Rapunzel created yessy ernidha sharry
Rapunzel created yessy ernidha sharryRapunzel created yessy ernidha sharry
Rapunzel created yessy ernidha sharry
Yesi Sari
 
12 2007-qd-btnmt
12 2007-qd-btnmt12 2007-qd-btnmt
12 2007-qd-btnmt
lehung0521
 
Slidesharetest
SlidesharetestSlidesharetest
Slidesharetest
성규 어
 
Practicum Presentation
Practicum Presentation Practicum Presentation
Practicum Presentation
radfatoma
 
เศรษฐกิจพอเพียง เรื่อง ฝายกั้นน้ำ
เศรษฐกิจพอเพียง เรื่อง ฝายกั้นน้ำเศรษฐกิจพอเพียง เรื่อง ฝายกั้นน้ำ
เศรษฐกิจพอเพียง เรื่อง ฝายกั้นน้ำ
maytakul
 

Viewers also liked (17)

Sand Stone
Sand StoneSand Stone
Sand Stone
 
Service
ServiceService
Service
 
Rapunzel created yessy ernidha sharry
Rapunzel created yessy ernidha sharryRapunzel created yessy ernidha sharry
Rapunzel created yessy ernidha sharry
 
Rev kkn
Rev kknRev kkn
Rev kkn
 
Mitaka lab cover
Mitaka lab coverMitaka lab cover
Mitaka lab cover
 
RAPUNZEL
RAPUNZELRAPUNZEL
RAPUNZEL
 
2012 ARQUO Marketplace
2012 ARQUO Marketplace2012 ARQUO Marketplace
2012 ARQUO Marketplace
 
ZGarci
ZGarciZGarci
ZGarci
 
Tools
ToolsTools
Tools
 
12 2007-qd-btnmt
12 2007-qd-btnmt12 2007-qd-btnmt
12 2007-qd-btnmt
 
Strategy of Emperer Saga & Kukai on Kyoto - Daikakuji-temple, Osawanoike-pond
Strategy of Emperer Saga & Kukai on Kyoto - Daikakuji-temple, Osawanoike-pondStrategy of Emperer Saga & Kukai on Kyoto - Daikakuji-temple, Osawanoike-pond
Strategy of Emperer Saga & Kukai on Kyoto - Daikakuji-temple, Osawanoike-pond
 
Slidesharetest
SlidesharetestSlidesharetest
Slidesharetest
 
Korona.POS Cloud Presentation
Korona.POS Cloud PresentationKorona.POS Cloud Presentation
Korona.POS Cloud Presentation
 
Genius Overview
Genius OverviewGenius Overview
Genius Overview
 
Sebi
SebiSebi
Sebi
 
Practicum Presentation
Practicum Presentation Practicum Presentation
Practicum Presentation
 
เศรษฐกิจพอเพียง เรื่อง ฝายกั้นน้ำ
เศรษฐกิจพอเพียง เรื่อง ฝายกั้นน้ำเศรษฐกิจพอเพียง เรื่อง ฝายกั้นน้ำ
เศรษฐกิจพอเพียง เรื่อง ฝายกั้นน้ำ
 

Similar to Chapter10

Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
pinkpreet_kaur
 
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
aquacare2008
 
C++ - UNIT_-_V.pptx which contains details about File Concepts
C++  - UNIT_-_V.pptx which contains details about File ConceptsC++  - UNIT_-_V.pptx which contains details about File Concepts
C++ - UNIT_-_V.pptx which contains details about File Concepts
ANUSUYA S
 
02 fundamentals
02 fundamentals02 fundamentals
02 fundamentals
sirmanohar
 
Student NameClassDateVBScript IP File ReportIn the space provide.docx
Student NameClassDateVBScript IP File ReportIn the space provide.docxStudent NameClassDateVBScript IP File ReportIn the space provide.docx
Student NameClassDateVBScript IP File ReportIn the space provide.docx
emelyvalg9
 
The program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxThe program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docx
oscars29
 

Similar to Chapter10 (20)

Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
Lab 1 Essay
Lab 1 EssayLab 1 Essay
Lab 1 Essay
 
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
 
C++ - UNIT_-_V.pptx which contains details about File Concepts
C++  - UNIT_-_V.pptx which contains details about File ConceptsC++  - UNIT_-_V.pptx which contains details about File Concepts
C++ - UNIT_-_V.pptx which contains details about File Concepts
 
02 fundamentals
02 fundamentals02 fundamentals
02 fundamentals
 
File management in C++
File management in C++File management in C++
File management in C++
 
File Handling in c++
File Handling in c++File Handling in c++
File Handling in c++
 
Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2
 
File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
Filepointers1 1215104829397318-9
Filepointers1 1215104829397318-9Filepointers1 1215104829397318-9
Filepointers1 1215104829397318-9
 
C- language Lecture 8
C- language Lecture 8C- language Lecture 8
C- language Lecture 8
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
 
Filehandling
FilehandlingFilehandling
Filehandling
 
Student NameClassDateVBScript IP File ReportIn the space provide.docx
Student NameClassDateVBScript IP File ReportIn the space provide.docxStudent NameClassDateVBScript IP File ReportIn the space provide.docx
Student NameClassDateVBScript IP File ReportIn the space provide.docx
 
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
 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
 
The program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxThe program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docx
 

Chapter10

  • 1. TYBSC (IT) Visual Basic Chapter-10 Data Files Q. 1. What is the difference between a Visual Basic project file and a data file?( 4 mrks ) Visual Basic project file Data File Each of our VB project file requires multiple Anything that we store on a hard disk is given files for the forms , standard code modules, its own unique name and is called a Data file. and project modules. In this, some situations we require large The file is made up of records one record for quantities of data or information to be each entity in the file. Each record can be processed. broken down further into fields Q. 2 What occurs when open statement is executed ?( 4 rks ) We can use open statement for both i.e. sequential and random access files. Open statement reserves file handle, also called a channel for reading from and writing to a file. The open statement associates number to the handle. A file handle is a unique path to file associated with a number from the open statement. Open statement associates a number to the handle after that we can use the file number to access the file. Similarly, we have to specify the mode in which we want to open the file. These mode can be read , write or both. Q. 3. List and explain the file modes for data files.(6 mrks ) File modes for data files are as follows: i) Append: Opens a file for sequential output starting at the end of file. ii) Input: Opens a file for sequential input, we can read from the file. iii) Output: Opens a file for sequential output, starting from beginning of file. iv) Random: Open a file for random read and write access. This mode allows to read and write to a file at any specified record boundaries. 1
  • 2. TYBSC (IT) Visual Basic Q. 4. What is the significance of file number?( 4 mrks ) A file number is used to maintain the files. In the project suppose we have large number of files , so instead of using the various file names we refer to the file numbers. Syntax is as follows: Open “filename” # 1 For ex. Open “Abc.txt” # 1 Above statement opens the file Abc.txt. It associates a file number one to abc.txt To refer to this file we can use this file number. Q. 5. Explain difference between the Output and Append modes.( 4 mrks ) Output Mode Append mode Opens a file for sequential output, starting It opens a file for sequential output, starting at from the beginning of the file. the end of the file. For Ex : For Ex: Private Sub Command_click() Private Sub Command_click() filenum = FreeFile Open “C: output.txt” filenum = FreeFile Open “C: output.txt” For Output As filenum For Append As filenum Print #filenum , text1.text Print #filenum , text1.text Close filenum Close filenum End Sub End Sub Q. 6. What is the format for the statements to read and write sequential files?( 6 mrks ) Sequential file contains data elements that are stored one after another in sequence. When we read the data from the disk, it must be read in the same sequence in which it was written. To read any particular element of data, all proceeding must first be read. As data elements are written on disk, string fields are enclosed in quotation marks and fields and separated by, records are generally terminated a carriage written character. 2
  • 3. TYBSC (IT) Visual Basic Input statement is used to read the data from the a sequential file. Syntax is : Input # intFileNumber , variable1 , variable2 ,… Input statement requires file number and variables to hold the data. For ex. Private Sub cmdRead_click() Dim intV1, intV2, intV3, as Integer Open “c:/seg.txt” for input as # 1 Input # 1 intV1, intV2, intV3 Close # 1 MsgBox “Seg.txt Contains “ &intV1, &intV2, &intV3 End Sub For writing purpose we use the write # statement to place data into a sequential data file. Before the write # statements can be executed , the file must be opened in either output mode or append mode. For append mode, the file pointer is placed at the end of file. If there are no records, the beginning of end of file. In output mode, the pointer is placed at the beginning of the file. Use output mode to create a new file ot write old data. Syntax is : Write # file number , list of fields Ex. Write # 1 , txtAmount.text , txtDescription.text , txtPrice.text Write # 2 , strAccount Q.7 . What function can be used to determine an available file number?( 4 mrks ) When we open a file, we must assign a file number to each file. For a small project, with one or two data files, most programmer‟s assign # 1 and # 2.But in larger project selecting a file number can be a problem. If our code will be part of larger project with code from other programmers and other libraries we must make same to avoid any conflicting file number. 3
  • 4. TYBSC (IT) Visual Basic To solve this problem we can allow the system to assign the next available file number use the FreeFile function to assign the next available file number to our file and we will never have conflict. Ex. Dim intFileNum as Integer intFileNum = FreeFile „ Get next available file number Open “Abc.txt” for output as # intFileNum Q. 8. When would an On Error statement be used?( 6 mrks ) We must place an On Error statement at the beginning of the any procedure where error might occur, such as before opening sequential file for input. An on error statement will trap the error and it will direct the execution control to the error trap level. Actually , there are four different statements that we can use when error occurs. i.Resume Next:It tells VB that if an error occurs,the program should simply skip to the next lineof the code and bypass the line where the error has occured. Example: Private sub cmdDelete_Click( ) on Error Resume Next Stop Kill txtFile 'Kill statement delete the specified file in the textbox if err.Number then MsgBox " such a file doesn't exit " Endif End Sub ii.Resume (Label Name ):This statement is used , if you want to transfer execution control.To some different location or you just want to ignore the error Example: 4
  • 5. TYBSC (IT) Visual Basic private sub cmdOpen_Click( ) OnError GoTo ErrorTrap set db = OpenDatabase("C:emp.mdb") Normal Exit: Exit Sub Error Trap: Msgbox " Failed to open the file " Resume NormalExit End sub iii.Resume :When Error occurs and if you want to give the user a chance to fix the error , In that caes above statement is used. Example: If your tries to access a floppy without putting it intothe disk drive , you application may ask you to insert it and then continue with the execution again. private sub cmdResume_Click( ) On Error Go To ErrorTrap MsgBox" Length of the file is " & FileLen( txtFile ) Normal Exit: Exit sub Error Trap: If err.Number then If MsgBox (" Floppy drive error try again ") = vbYes then Resume Endif End Sub iv.The errObject:Every time an error occurs vb creates an object, which contain erroe information this error object can be used to retrive the information about the type of error , which has occured the important properties of errorobject are as follows: 5
  • 6. TYBSC (IT) Visual Basic property Description 1.Number Identifies the specified error that occurs. 2.Description Take description of the error. 3.Source A String identifying the name of the object that are generated the error Q.9. Explain the function and use of Err object.( 6 mrks ) Every time an error occurs VB creates an object, which contains error information. This Err object can be used to retrieve the information about the type of error which has occured. Properties of Err Object are as follows: Property Description Number Indentifies specified error that occur. Description Takes description of the error. Source A string identifying name of the object that has generated error. Methods of Err Object are as Follows: Method Description Clear Clears any information contain in the error object. Raise This method can be used to test the error handling code. We can use this method to generate run time errors. Q. 10 What are the difference between a random file and a sequential file? ( 6 mrks ) Random Access File Sequential Access File 6
  • 7. TYBSC (IT) Visual Basic Random Access file is made up of identical Sequential Access files are accessed by line size. Each record is made up of identical size. by line for applications that manipulate text files. Get and Put statements are used to access Input, Write statements are used to access the random access file. sequential access file. For ex. For ex. Private Sub Form_Load() Private Sub Command1_Click() RecorLen = Len(product) fileNum= FreeFile Open FileNum = FreeFile “C:output.txt” for Output As fileNum Open “c:Product.dat” for Random as FileNum Print# fileNum , text1.text Len= RecordLen Close fileNum End Sub Q. 11. What does updating a data file mean?( 4 mrks ) A file update generally consists of routine to add records, update records, delete records and browse through records. The procedures for these options might be selected from a command button or a menu command. Each routine must display the fields from the file, so we will use one form and refer to it as the data form. This form contains text boxes for each field of a record along with the appropriate labels. Q.12 Explain Get statement and put statement.( 4 mrks ) This two statement are used to access Random Access Files. Get is used to read particular record from a file.Similary,Put is used to write a particular record in a file. Syntax: Put # intFileNum , intRecordNum , variable Get # intFileNum , intRecordNum , variable Both of the above use RecordNum , which indicates RecordNumber ,you want to works with the variable can be of any datatype , it can be array or userdefine datatype. Example: Private sub cmdWrite_Click( ) Dim Ctr As integer 7
  • 8. TYBSC (IT) Visual Basic Open" C: ABC.txt " for Random As # 1Len=5 for intCtr =1 to 5 Put #1, intCtr , intCtr Next intCtr Close#1 End Sub 8