VB NOTES PART 20

VB NOTES PART 20 - Line = input.ReadToEnd line is “here...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
4/19 Classes for reading and writing files are found in system.IO, so first thing in VB code: Imports system.IO Steps in file processing a file: 1. Declare Object StreamReader or StreamWriter 2. Create object Associates the object with a physical file file pointer “Opens” the file New Hello 3. Use methods for reading or writing file There 4. Close file ------ don’t leave file open 126 Declare object/ creating object Dim input as StreamReader = New StreamReader (“calendar.txt ”) ----- “” is the name of the file Methods for reading Dim line As String Line = input.ReadLine () ------------------- the value of the line is “hello” and after that the file pointer point to the next line “There” Line = input.Read ()
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Line = input.ReadToEnd () ------ line is “here 126” Line = input.Peek () -----returns next character, doesn’t move file pointer Basic file-reading loop Dim nextLine As String Do Until input.EndOfStream nextLine = input.ReadLine () ‘ process line Loop Alternatively: Dim words As String () ------------------ string array Words = nextLine.Split () Close file Input.Close () Writing Dim output As StramWriter = New StramWriter (“calendar.txt”. True ) ----Append mode If true, add new stuff to end of file If false, overwrite existing file Output.WriteLine (id number & “ “ & Last Name & “ “ & phone Output.Write (“hello”) add line feed Output.Close ()...
View Full Document

This note was uploaded on 12/01/2011 for the course 6K 226 taught by Professor Staff during the Fall '10 term at University of Iowa.

Page1 / 2

VB NOTES PART 20 - Line = input.ReadToEnd line is “here...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online