Private Sub cmdAverage_Click()
Dim
intAtBats
As Integer
Dim
intHits
As Integer
Dim
sngBattingAverage
As Single
intAtBats = Val(InputBox("Enter Number of at bats", "At
Bats"))
intHits = Val(InputBox("Enter Number of hits", "Hit
Number"))
If
intAtBats
> 0
Then
sngBattingAverage = BattingAverage(intAtBats,
intHits)
MsgBox "Batting Average " &
Str(sngBattingAverage), _
vbOKOnly, "Average“
Else
MsgBox "No at bats", vbOKOnly, "Zero At Bats“
End If
End Sub
Public Function
BattingAverage(AtBats
As Integer,
Hits
As Integer) _
As Single
BattingAverage = Hits / AtBats
End Function |