Do Not Hand out This Schedule; Hand out Generic Syllabus Instead

Do Not Hand out This Schedule; Hand out Generic Syllabus Instead

<p>CS213 - Applications of computer programming, Lecture 21</p><p>Sequential files</p><p>1. Reading a file</p><p>Private Sub Button1_Click(...) Handles Button1.Click Dim Filename, Line As String Dim I As Integer Dim sr As IO.StreamReader Filename = InputBox("Enter the file name") sr = IO.File.OpenText(Filename) For I = 1 To 5 Line = sr.ReadLine lstOutput.Items.Add(Line) Next I sr.Close() End Sub</p><p>2. Writing on a file (creating a new file)</p><p>Private Sub Button1_Click(...) Handles Button1.Click Dim Filename, Line As String Dim I As Integer Dim sr As IO.StreamWriter Filename = InputBox("Enter the file name") sr = IO.File.CreateText(Filename) For I = 1 To 5 Line = InputBox("Enter a line of text") sr.WriteLine(Line) Next I sr.Close() End Sub</p><p>3. Appending a file</p><p>Private Sub Button1_Click(...) Handles Button1.Click Dim Filename, Line As String Dim I As Integer Dim sr As IO.StreamWriter Filename = InputBox("Enter the file name") sr = IO.File.AppendText(Filename) For I = 1 To 5 Line = InputBox("Enter a line of text") sr.WriteLine(Line) Next I sr.Close() End Sub</p><p>4. The Peek method</p><p>Private Sub Button1_Click(...) Handles Button1.Click Dim Filename, Line As String Dim sr As IO.StreamReader Filename = InputBox("Enter the file name") sr = IO.File.OpenText(Filename) Do While sr.Peek <> -1 Line = sr.ReadLine lstOutput.Items.Add(Line) Loop sr.Close() End Sub</p><p>5. Files with numeric and combined data</p><p>5.1. Creating a file with line numbers</p><p>Private Sub Button1_Click(...) Handles Button1.Click Dim Filename, Line As String Dim I As Integer Dim sr As IO.StreamWriter Filename = InputBox("Enter the file name") sr = IO.File.CreateText(Filename) For I = 1 To 5 Line = InputBox("Enetr nanme") sr.WriteLine(I & Chr(9) & Line) Next I sr.Close() End Sub</p><p>5.2. Printing the file with line numbers</p><p>Private Sub Button1_Click(...) Handles Button1.Click Dim Filename, Line As String Dim Name As String Dim Num As Integer Dim sr As IO.StreamReader Filename = InputBox("Enter the file name") sr = IO.File.OpenText(Filename) Do While sr.Peek <> -1 Line = sr.ReadLine Num = CInt(Line.Substring(0, 2)) Name = Line.Substring(2) lstOutput.Items.Add(Score & Name) Loop sr.Close() End Sub</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us