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

Info icon This 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 ()
Image of page 1

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern