Question
Cricket is a popular sport in British Commonwealth countries, like Australia, and India. Each match has two sides (teams), as usual. There are four components
Cricket is a popular sport in British Commonwealth countries, like Australia, and India. Each match has two sides (teams), as usual. There are four components to a sides score:
- Boundaries (sixes): 6 points each
- Boundaries (fours): 4 points each
- Singles: 1 point each
- Sundries: 1 point each
Write a VBA program to compute a score given the information above. When the worksheet opens:
The user enters four values, clicks Run, and the program computes the score. For example:
All input values must be numeric and zero or more. If there are errors, show messages next to each erroneous cell. For example:
Be sure to clear old error messages and output when the program runs.
- Do not change any code in the sub cmdRun_Click. Do not add, change, or remove anything.
- Do not change the declarations of any sub.
- Put code in every sub given in the starting worksheet, and call every sub at least once.
- Put any code you want in the subs, apart from cmdRun_Click, which must remain unchanged.
- Add any new subs you want.
'Below is my code: Option Explicit
Private Sub cmdRun_Click() Dim sixes As Integer Dim fours As Integer Dim singles As Integer Dim sundries As Integer Dim inputOk As Boolean Dim score As Integer 'Clear errors and output. clearErrorsAndOutput 'Get valid inputs. getValidInputs sixes, fours, singles, sundries, inputOk If Not inputOk Then End End If 'Compute the score. computeScore sixes, fours, singles, sundries, score 'Output the score. outputScore score End Sub
'Clear old error messages and output. Sub clearErrorsAndOutput()
End Sub
'Get and validate user inputs. Show error messages. 'Params: ' sixes: number of sixes scored, e.g., 2 (output) ' fours: number of fours scored, e.g., 3 (output) ' singles: number of singles scored, e.g., 13 (output) ' sundries: number of sundries awarded, e.g., 2 (output) ' inputOK: true if all inputs valid, otherwise false (output) Sub getValidInputs(sixes As Integer, fours As Integer, singles As Integer, sundries As Integer, inputOk As Boolean)
End Sub
'Check that the value in a cell is a positive number. 'Show error messages. 'Params: ' row: the row of the cell to check, e.g., 3 (input). ' dataLabel: text describing the data in the cell, e.g., "pounds" (input). ' dataOK: returns true if the data is OK, false if it is not (output). Sub checkCellValue(row As Integer, dataLabel As String, dataOK As Boolean)
End Sub
'Compute the score. 'Params: ' sixes: number of sixes scored, e.g., 2 (input) ' fours: number of fours scored, e.g., 3 (input) ' singles: number of singles scored, e.g., 13 (input) ' sundries: number of sundries awarded, e.g., 2 (input) ' score: score, e.g., 39 (output) Sub computeScore(sixes As Integer, fours As Integer, singles As Integer, sundries As Integer, score As Integer)
End Sub
'Output the score. 'Params: ' score: score, e.g., 39 (input) Sub outputScore(score As Integer)
End Sub
1 What's the cricket score? 3 Boundaries (six): 4 Boundaries (four): 5 Singles: 6 Sundries: Run 10 ScoreStep 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