36
Presentation on File Handling

Filehandling

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Filehandling

Presentationon

File Handling

Page 2: Filehandling

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

Page 3: Filehandling

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.

Page 4: Filehandling

Types Of Files

There are three types of files.

1) Sequential Access Files

2) Random Access Files

3) Binary Files

Page 5: Filehandling

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.

Page 6: Filehandling

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.

Page 7: Filehandling

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.

Page 8: Filehandling

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.

Page 9: Filehandling

Operations on File

Page 10: Filehandling

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 .

Page 11: Filehandling

Opening A File

Open statement is used to open a file.

Open*filename*for mode as # filenumber [len=recordlength]

Syntax :

Page 12: Filehandling

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.

Page 13: Filehandling

Closing A File

Close statement is used to close a file.

Close [filenumberlist]

Syntax :

• In syntax, Filenumberlsit is one or more file numbers separated by commas.

Page 14: Filehandling

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.

Page 15: Filehandling

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.

Write # filenumber, [itemlist]

Syntax

Page 16: Filehandling

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.

Input # filenumber, itemlist

Syntax

Page 17: Filehandling

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.

Page 18: Filehandling

Contd..

.

Open filename for append as #1

Syntax

Page 19: Filehandling

Detecting the end of the file

The EOF function detects when the end of file has been

reached.

The function proves true if the end of file has been

reached or false if the end of file has not been reached.

EOF(file number)

Syntax

Page 20: Filehandling

Application on file handling

Page 21: Filehandling
Page 22: Filehandling

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.

Page 23: Filehandling

How to draw a shape

Shape option

•Select the shape option from the toolbox.

•Then go to shape properties and select any

option.

Page 24: Filehandling

Coding Of this Form

Private Sub cmdappend_Click()

Unload Me

frmappend.Show

End Sub

Private Sub cmdclose_Click()

Unload Me

End

End Sub

Page 25: Filehandling

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

Page 26: Filehandling
Page 27: Filehandling

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

Page 28: Filehandling

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

Page 29: Filehandling

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]

Page 30: Filehandling

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.

Page 31: Filehandling
Page 32: Filehandling
Page 33: Filehandling

CodingPrivate Sub cmdappend_Click()Open "d:\aman.txt" For Append As #1productname = "laptop"companyname = "samsung"price = 33000Write #1, productname, companyname, priceClose #1End Sub

Private Sub cmdclose_Click()Unload MeEndEnd Sub

Page 34: Filehandling
Page 35: Filehandling

CodingPrivate Sub cmdclose_Click()Unload MeEndEnd Sub

Private Sub cmdwrite_Click()Open "d:\aman.txt" For Output As #1productname = "laptop"companyname = "samsung"price = 33000Write #1, productname, companyname, priceClose #1End Sub

Page 36: Filehandling

Thank You !!!!!!!!