Page 176 - Open Soource Technologies 304.indd
P. 176

Event Driven Programming


                              name = sr.ReadLine
                              numLines += 1
                            Loop
                            upperBound = numLines -1
                            sr.Close()
                            ‘Specify the title bar of the form
                            Me.Text = “First “  & upperBound + 1  & “ Super Bowls”
                            ‘Specify the caption of the Next Winner button
                            btnNextWinner.Text = “Add Winner of Game “  & upperBound + 2
                            ‘Specify the size of the array and fill it with the entries of the
                          file
                            ReDim teamName(upperBound)
                            sr = IO.File.OpenText(“SBWINNERS.TXT”)
                            For i As Integer = 0 To upperBound
                              teamName(i) = sr.ReadLine
                            Next
                            sr.Close()
                          End Sub
                          Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
                            ‘Display the numbers of the games won by the team in the text box
                            lstGamesWon.Items.Clear()
                            For i As Integer = 0 To upperBound
                              If teamName(i) = txtName.Text Then
                                lstGamesWon.Items.Add(i + 1)
                              End If
                            Next
                          End Sub

                          Private Sub btnNextWinner_Click(...) Handles btnNextWinner.Click
                            ‘Add winner of next Super Bowl to the array
                            Dim prompt As String
                            upperBound += 1
                            ‘Add one more element to the array
                            ReDim Preserve teamName(upperBound)
                            ‘Request the name of the next winner
                            prompt = “Enter winner of game #”  & upperBound + 1
                            teamName(upperBound) = InputBox(prompt, , “”)
                            ‘Update the title bar of the form and the caption of the button
                            ‘Note: “Me” refers to the form.



                          170                    LOVELY PROFESSIONAL UNIVERSITY
   171   172   173   174   175   176   177   178   179   180   181