Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write Code In Visual Basic Create an application that accepts one or more scores

ID: 3880958 • Letter: W

Question

Write Code In Visual Basic

Create an application that accepts one or more scores from the user. Each time a score is added, the score total, score count, minimum score, maximum score and average score are calculated and displayed.

Incorporate the following features:

DON’T USE AN ARRAY – You don’t need one

Your application should not crash, so make sure the user inputs valid data. I.e., the Score input cannot be text.

After you process the addition of the score, tell VB to Clear the Score Textbox, and move the cursor back to the score textbox to make it easier to enter the next number.

The Enter key should be equivalent to hitting the Add button

The Escape key should be equivalent to hitting the Exit button.

Add comments at the top of each subroutine.

Show the average to 2 decimal places.

Have a button that will clear all the values

Add color to the form

Accumulate Scores Pelc Score Total: Score Count: Minimum Score Maximum Score Average Score Clear ScoresExit

Explanation / Answer

Inorder to set the background color to form, we need to change the BackColor property of the Form in the properties window.

For Add button to work when we press Enter, set the AcceptButton property of the Form to the Add Button in our form.

Similarly for Escape to work as exit, we set the ExitButton property of the Form to Exit Button in our form.

Below is the VB code which acquires what is asked:

Public Class AccumulateScoresForm

    'Declaring variables

    Dim score_total As Double

    Dim score_entered As Double

    Dim score_count As Integer

    Dim min_score As Double

    Dim max_score As Double

    Dim avg_score As Double

    'This method is called when we run the application and the form is loaded

    'As the form is loaded we initialise the score_total as 0

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        score_total = 0.0

    End Sub

    'This method is called when user presses the Add button

    'Perform activities such as taking in the entered score, and if valid, increment the count

    'Calculates the total by adding the score entered to the previous total.

    'If user has entered only 1 number i.e score_count = 1 then max and min score is that value only.

    'Once user enters more numbers, every number is checked with previous max and min and the max

    ' and min values are set accordingly.

    Private Sub AddButton_Click(sender As Object, e As EventArgs) Handles AddButton.Click

        If Not IsNumeric(Score_InputTextBox.Text) Then

            MessageBox.Show("Please enter valid score")

        Else

            score_entered = Score_InputTextBox.Text

            score_count += 1

            If (score_count = 1) Then

                min_score = score_entered

                max_score = score_entered

            Else

                If score_entered < min_score Then

                    min_score = score_entered

                End If

                If score_entered > max_score Then

                    max_score = score_entered

                End If

            End If

            score_total += score_entered

            avg_score = score_total / score_count

            Score_CountTextBox.Text = score_count

            Score_TotalTextBox.Text = score_total

            Min_ScoreTextBox.Text = min_score

            Max_ScoreTextBox.Text = max_score

            Avg_ScoreTextBox.Text = avg_score.ToString("#,0.00")

        End If

        Score_InputTextBox.Clear()

    End Sub

    Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click

        Close()

    End Sub

    Private Sub Clear_ScoreButton_Click(sender As Object, e As EventArgs) Handles Clear_ScoreButton.Click

        Score_InputTextBox.Clear()

        Score_CountTextBox.Clear()

        Score_TotalTextBox.Clear()

        Min_ScoreTextBox.Clear()

        Max_ScoreTextBox.Clear()

        Avg_ScoreTextBox.Clear()

        score_count = 0

        score_total = 0

        min_score = 0

        max_score = 0

        avg_score = 0

        Score_InputTextBox.Select()

    End Sub

End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote