Contestant Solution’s Codes: Public Class frmMain
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() End Sub
Private Sub btnWrite_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnWrite.Click ' writes a name to a sequential access file
' declare a StreamWriter variable Dim outfile As IO.StreamWriter
' open the file for append outfile = IO.File.AppendText("Contestant.txt") ' write the name on a separate line in the file outfile.WriteLine(txtName.Text) ' close the file outfile.Close() ' clear the list box and then set the focus lstContestants.Items.Clear() txtName.Focus() End Sub
Private Sub btnRead_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRead.Click ' reads names from a sequential access file ' and displays them in the interface
' declare variables Dim infiles As IO.StreamReader Dim strname As String
' clear previous names from the list box lstContestants.Items.Clear()
' determine whether the file exists If IO.File.Exists("Contestant.txt") Then 'open the file for input infiles = IO.File.OpenText("Contestant.txt") 'process loop instructions until end of file Do Until infiles.peek = -1 'read a name strname = infiles.ReadLine 'add name to a listbox lstContestants.Items.Add(strname) Loop infiles.Close() Else MessageBox.Show("Can't find the file", "Game show contestants", MessageBoxButtons.OK, MessageBoxIcon.Information) End If
End Sub
Private Sub txtName_Enter(ByVal sender As Object, ByVal e