Download presentation
Presentation is loading. Please wait.
1
Ch 10 Sequential Access Files
2
Files Text files Reading a file Writing to a file Input files
Output files Sequential access files
3
Creating a Stream for Output
Declare a StreamWrite Variable Dim outFile As IO.StreamWriter
4
Opening a File for Output
Opening a sequential access file IO.File.CreateText opens a file for output IO.File.AppendText opens a file for append Examples outFile = IO.File.CreateText(“F:\\VB2015\Chap10\employee.txt”) outFile = IO.File.AppendText(“report.txt”)
5
Writing Data to a File
6
Creating a Stream for Input
‘ declare a StreamReader variable Dim inFile As IO.StreamReader
7
Opening a File for Input
‘ Open a sequential access file inFile = IO.File.OpenText(“report.txt”)
8
Checking the Existence of the Input File
‘ determine whether the report.txt file exists ‘ in the current project folder If IO.File.Exists(“report.txt”) Then inFile = IO.File.OpenText(“report.txt”) Else MessageBox(“Can’t fine the report.txt file”, _ “Output”, MessageBoxButtons.OK, _ MessageBoxIcon.Information) End IF
9
Reading Data From a File
‘ read a line of text message = inFile.ReadLine ‘ read data from a file line by line Do Until inFile.Peek = -1 line = inFile.ReadLine MessageBox.Show(line) Loop
10
Contestant names appear in the Contestants box
An Example Contestant names appear in the Contestants box
11
Names contained in the contestants.txt file
Data in the File Names contained in the contestants.txt file
12
An Example (Cont.)
13
An Example (Cont.)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.