Question
Neeb Visual Basic code for the following question Extra 8-1 Display a test scores array In this exercise, youll enhance the Score Calculator form of
Neeb Visual Basic code for the following question
Extra 8-1 Display a test scores array In this exercise, youll enhance the Score Calculator form of extra exercise 4-2 so it saves the scores the user enters in an array and then lets the user display the sorted scores in a dialog box. 1. Open the ScoreCalculator project in the Extra Exercises\Chapter 08\ScoreCalculator With Array directory. This is the Score Calculator form from extra exercise 4-2 with data validation and exception handling added. 2. Declare a module-level variable for an array that can hold up to 20 scores. 3. Modify the Click event handler for the Add button so it adds the score thats entered by the user to the next element in the array. To do that, you can use the score count variable to refer to the element. 4. Move the Clear Scores button as shown above. Then, modify the Click event handler for this button so it removes any scores that have been added to the array. The easiest way to do that is to create a new array and assign it to the array variable. 5. Add a Display Scores button that sorts the scores in the array, displays the scores in a dialog box, and moves the focus to the Score text box. Be sure that only the elements that contain scores are displayed. 6. Test the application to be sure it works correctly.
please see my VB Code below
Public Class Form1
'Declerations Dim Score(20) As Integer 'Dim score As New List(Of () Dim Total As Integer Dim Count As Integer Dim Average As Double
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
If tboScore.Text <> "" Then
For I As Integer = 0 To 20 If Score(I) = CInt(I) Then Score(I) = CInt(lboResult.Text) Exit Sub End If Next
tboScoreTotal.Text = CType(Total, String) tboScoreCount.Text = CType(Count, String) Average = (Total / Count) tboAverage.Text = CType(Average, String) lboResult.Items.Add(tboScoreTotal.Text) tboScore.Clear() End If lboResult.Text = Convert.ToString(Total) End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
tboScoreTotal.Text = Total.ToString() tboScoreTotal.Text = CType(0, String) tboScoreCount.Text = CType(0, String) tboAverage.Text = CType(0, String)
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If tboScore.Text <> "" Then
For I As Integer = 0 To 20 If Score(I) = CInt(I) Then Score(I) = CInt(lboResult.Text) Exit Sub End If Next End If
lboResult.Items.Add(Score)
lboResult.Text = Convert.ToString(Score) End Sub
Private Sub BtnAscending_Click(sender As Object, e As EventArgs) Handles BtnAscending.Click lboResult.Items.Clear() Array.Sort(Score) displaySortedScores() End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click lboResult.Items.Clear() Array.Sort(Score) Array.Reverse(Score) displaySortedScores() End Sub Private Sub displaySortedScores() For Each item As Integer In Score lboResult.Items.Add(Score) Next End Sub
End Class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started