Question

rcises-3.pdf - Adobe Acrobat Reader DC View Window Help Tools Extra exerases-3.pdf X 14 Extra exercises tor Murachs Visual Basie 2015 Extra 8-1 Display a test scores array In this exercise, youll enhance the Score Caleulator 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. Elle-a Sortedd Scores 帽Score Calculator Scow 98 89 92 96 97 98 Score total: 472 Score count Awerage 94 Display Scores Cear Scores OK Exdt Open the ScoreCalculator project in the Extra Exercises Chapter 08 ScoreCalculator With Amay 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 aay 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 Move the Clear Scores button as shown above Then. modity 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 4. 5. Add a Display Scores burton that sorts the scores in the array. displays the scores in a dialog box. and moves the tocus 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 훼 0 0 ●のChapter 4 . How to e Extra xercises-3.pd.. Desktop

must be visual basic code please include any properties that have to be changed.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the solution:

frmMain.vb

Public Class frmMain
    'Create a array list and initialize
    Dim lNumbers As List(Of Integer) = New List(Of Integer)
    Dim score As Integer
    Dim totalScore As Integer
    Dim scoreCount As Integer
    Dim average As Double
    Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CenterToScreen()
    End Sub

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

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        'check for the invalid entry
        If Not (Integer.TryParse(txtScore.Text, score)) Then
            MessageBox.Show("Invalid score")
        ElseIf Not (Integer.TryParse(txtTotalScore.Text, totalScore)) Then
            MessageBox.Show("Invalid total score")
        ElseIf Not (Integer.TryParse(txtScoreCount.Text, scoreCount)) Then
            MessageBox.Show("Invalid score count")
        ElseIf Not (Integer.TryParse(txtAverage.Text, average)) Then
            MessageBox.Show("Invalid average")
        Else
            If lNumbers.Count - 1 < 20 Then
                lNumbers.Add(score) 'added the value to the list
                MessageBox.Show("Added")
            Else
                MessageBox.Show("cannot insert more than 20 value in array")
            End If

        End If
    End Sub

    Private Sub btnClearScores_Click(sender As Object, e As EventArgs) Handles btnClearScores.Click
        'clear the all text field and the array list
        txtScore.Text = ""
        txtScoreCount.Text = ""
        txtTotalScore.Text = ""
        txtAverage.Text = ""
        lNumbers.Clear()
    End Sub

    Private Sub btnDisplayScores_Click(sender As Object, e As EventArgs) Handles btnDisplayScores.Click
        lNumbers.Sort() 'sort the list
        Dim obj As New frmSortedScore 'create object to display value to another form
        obj.score = lNumbers 'send the value to another form
        obj.Show() 'show the form
    End Sub
End Class

frmSortedScore.vb

Public Class frmSortedScore
    Public Property score As List(Of Integer)

    Private Sub frmSortedScore_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        lblScore.Text = ""
        For i = 0 To score.Count - 1
            lblScore.Text &= score(i).ToString & Environment.NewLine
        Next
    End Sub

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

output:

면 Score Calculator Sort- Score 98 Add Pelc 89 92 96 97 98 Score Total 472 Score Count 5 Average 94 Display Clear Scores OK Exit

Add a comment
Know the answer?
Add Answer to:
must be visual basic code please include any properties that have to be changed. rcises-3.pdf -...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Visual Studio Code C# Well Document everyline saying what the code does. Include designer code and...

    Visual Studio Code C# Well Document everyline saying what the code does. Include designer code and .cscode Extra 6-1 Create a simple calculator In this exercise, you'l1 create a form that accepts two operands and an operator from the user and then performs the requested operation. Simple Calculator Operand 1: 86 Operator Operand 2 11.11 Resut 7.7408 1. Start a new project named SimpleCalculator in the Extra Exercises Chapter 06SimpleCalculator directory 2. Add labels, text boxes, and buttons to the...

  • Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb...

    Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb Public Class frmNewItem Public InvItem As InvItem Private Sub frmNewItem_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.LoadComboBox() End Sub Private Sub LoadComboBox() cboSizeOrManufacturer.Items.Clear() If rdoPlant.Checked Then cboSizeOrManufacturer.Items.Add("1 gallon") cboSizeOrManufacturer.Items.Add("5 gallon") cboSizeOrManufacturer.Items.Add("15 gallon") cboSizeOrManufacturer.Items.Add("24-inch box") cboSizeOrManufacturer.Items.Add("36-inch box") Else cboSizeOrManufacturer.Items.Add("Bayer") cboSizeOrManufacturer.Items.Add("Jobe's") cboSizeOrManufacturer.Items.Add("Ortho") cboSizeOrManufacturer.Items.Add("Roundup") cboSizeOrManufacturer.Items.Add("Scotts") End If End Sub Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click If IsValidData() Then InvItem = New InvItem(CInt(txtItemNo.Text),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT