Wednesday, November 3, 2010

Reading data from a Sequential Access File

HOW TO: Declare a StreamReader Variable
Syntax
{Dim | Private} streamReaderVariableName As IO.StreamReader

Example
Dim inFile As IO.StreamReader
declares a StreamReader variable named inFile.

HOW TO: Create a StreamReader Object
Syntax
IO.File.OpenText(fileName)

Example
inFile = IO.File.OpenText(“report.txt”)
opens the report.txt file for input, creates a StreamReader object and assigns it to the inFile variable.

HOW TO: Read data from a sequential access file
Syntax
streamReaderVariableName.ReadLine

Example
Dim message As String
message = inFile.ReadLine
reads a line of text from the file associated with the inFile variable and assigns the line, excluding the newline character, to the message variable.

No comments:

Post a Comment