Problems - Correcting Logic and Code Errors
The following sample of code contains errors. Rewrite the incorrect statements to correct all errors.
Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
' display the contents of the students.txt file
' declare variables
Dim inFile As IO.StreamWriter
Dim strStudent As String
' clear previous students from the Students box
lblStudents.Text = String.Empty
' determine whether the file exists
If IO.Exists("students.txt") = True Then
' open the file for input
inFile = IO.File.ReadText("students.txt")
' process loop instructions until end of file
Do Until inFile.Peek -1
' read a student line
strStudent = inFile.ReadLine
' display the student
lblStudents.Text = lblStudents.Text &
strStudent & ControlChars.NewLine
Loop
' close the file
Me.Close()
Else
MessageBox.Show("File not found","Students",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
End Sub
Correct Answer:
Verified
View Answer
Unlock this answer now
Get Access to more Verified Answers free of charge
Q41: Write the code to declare a variable
Q45: Describe two advantages to programmers of using
Q46: Write a Structure statement that defines a
Q48: Write the code to declare a variable
Q49: An application contains the Structure statement shown
Q51: Case-Based Critical Thinking Questions Case 1 -
Q52: Write the code to declare a variable
Q55: Write an If clause that determines whether
Q55: Case-Based Critical Thinking Questions Case 1 -
Q56: Write the statement that would remove the
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents