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

Fix the code: private Sub btnSoftball_Click(ByVal sender As System.Object, ByVal

ID: 3828678 • Letter: F

Question

Fix the code: private Sub btnSoftball_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSoftball.Click Dim decHits As Decimal = 210 Dim decTimesAtBat As Decimal = 428 Dim decBattingAverage As Decimal decBattingAverage = BattingAverage(decHits, decTimesAtBat) lblHits.Text = "The batting average is " & decBattingAverage.ToString() End Sub Private Function BattingAverage(ByVal decHitsCount As Decimal, ByVal decNumberAtBat) Dim decAverageAtBat As Decimal decAverageAtBat = decHitsCount/decNumberAtBat End Function

Explanation / Answer

This Code is made in VB.NET with a Button and a Label.

All variables are Decimal Numbers(Number which has Decimal Point).

Taken one function of Name BattingAverage() to calculate Batting Average & it has two parameters ie decHitsCount & decNumberAtBat

For Each line i will add Comment to describe meaning of each line .To add Comment we use '  opearator in VB.NET.

Private Sub btnSoftBall_Click(sender As Object, e As EventArgs) Handles btnSoftBall.Click

'This is a subProcedure (ie block to execute Code after cliciking a button) of given Button (btnSoftBall) with an 'event Click

. Dim decHits As Decimal = 210

'declared a variable with name decHits as decimal number with Value 210 to show number of hits

Dim decTimesAtBat As Decimal = 428

'declared a variable with name decTimesAtBat as decimal number with Value 428 to show how many times player has come to bat

Dim decBattingAverage As Decimal

' Declared a varible with name decBattingAverage to hold the return value of function BattingAverage() after exceuting line

decBattingAverage = BattingAverage(decHits, decTimesAtBat) 'Declaration of Function

'Passing two values to function BattingAverage(decHits,decTimesAtBat)


lblHits.Text = "The Batting average is " & decBattingAverage.ToString()

'Showing the output using LABEL of name lblHits.

'using ToString() function to show output in string format

End Sub


Private Function BattingAverage(ByVal decHitsCount As Decimal, ByVal decNumberAtBat As Decimal)

'this is the definition of Function BattingAverage() to calculate Average & has two Parameters decHitsCount & decNumberAtBat

Dim decAverageAtBat As Decimal 'Decimal varible to hold calcaulted answer / output
decAverageAtBat = decHitsCount / decNumberAtBat

' above Formula is to calculate Average by dividing decHitsCount by decNumberAtBat

BattingAverage = decAverageAtBat 'Returning output value to main part to display an output
End Function