Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Public Class Form1 Dim total As Integer = 0 Dim count As Integer = 0 Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click

Public Class Form1

Dim total As Integer = 0 Dim count As Integer = 0

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click Try If IsValidData() Then Dim score As Integer = CInt(txtScore.Text) total += score count += 1 Dim average As Integer = CInt(Math.Round(total / count, 0, MidpointRounding.AwayFromZero)) txtScoreTotal.Text = total.ToString txtScoreCount.Text = count.ToString txtAverage.Text = average.ToString txtScore.Select() End If Catch ex As Exception MessageBox.Show(ex.Message & vbCrLf & vbCrLf & ex.GetType().ToString & vbCrLf & ex.StackTrace, "Exception") End Try End Sub

Public Function IsValidData() As Boolean Return _ IsPresent(txtScore, "Score") AndAlso IsInt32(txtScore, "Score") AndAlso IsWithinRange(txtScore, "Score", 1, 100) End Function

Public Function IsPresent(textbox As TextBox, name As String) _ As Boolean If textbox.Text = "" Then MessageBox.Show(name & " is a required field.", "Entry Error") textbox.Select() Return False Else Return True End If End Function

Public Function IsInt32(textbox As TextBox, name As String) _ As Boolean Dim number As Integer = 0 If Int32.TryParse(textBox.Text, number) Then Return True Else MessageBox.Show(name & " must be an integer.", "Entry Error") textbox.Select() textbox.SelectAll() Return False End If End Function

Public Function IsWithinRange(textbox As TextBox, name As String, min As Decimal, max As Decimal) As Boolean Dim number As Decimal = CDec(textbox.Text) If number < min OrElse number > max Then MessageBox.Show(name & " must be between " & min & " and " & max & ".", "Entry Error") textbox.Select() textbox.SelectAll() Return False Else Return True End If End Function

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click total = 0 count = 0 txtScore.Text = "" txtScoreTotal.Text = "" txtScoreCount.Text = "" txtAverage.Text = "" txtScore.Select() End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub End Class

1. Reenter the code from above into the text box.

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. 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.

7. Paste your code into the text box below.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions