Problems: Correcting Logic and Code ErrorsThe 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
What will be an ideal response?
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 variablesDim inFile As IO.StreamReaderDim strStudent As String' clear previous students from the Students boxlblStudents.Text = String.Empty' determine whether the file existsIf IO.File.Exists("students.txt") = True Then' open the file for inputinFile = IO.File.OpenText("students.txt")' process loop instructions until end of fileDo Until inFile.Peek = -1' read a student linestrStudent = inFile.ReadLine' display the studentlblStudents.Text = lblStudents.Text &strStudent & ControlChars.NewLineLoop' close the fileinFile.Close()ElseMessageBox.Show("File not found","Students",MessageBoxButtons.OK,MessageBoxIcon.Information)End IfEnd Sub
You might also like to view...
Give an example of a schedule in which these cursors give di?erent results even when the transaction is executing in isolation.
What will be an ideal response?
Where possible, determine the number of significant digits for the following numbers:
0.00001
In SharePoint, the ________ setting is important when team members in different countries are trying to coordinate their schedules for meetings and other events
A) time zone B) locale C) time format D) sort order
Multiple fields may be used when sorting records.
Answer the following statement true (T) or false (F)