17. Open the Bonus Solution (Bonus Solution.sln) file contained in the VbReloade
ID: 3674063 • Letter: 1
Question
17. Open the Bonus Solution (Bonus Solution.sln) file contained in the VbReloaded2012
Chap05Bonus Solution folder. (4, 6, 8, 10)
a. The user will enter the sales amount as an integer in the salesTextBox, which
INTRODUCTORY
b. The calcButton_Click procedure should display the salesperson’s bonus. A
should accept only numbers and the Backspace key. Code the appropriate event
procedure.
salesperson with sales from $0 through $3,500 receives a 1% bonus. A salesperson
with sales from $3,501 through $10,000 receives a 5% bonus. A salesperson whose
sales are more than $10,000 receives a 10% bonus. The procedure should display
the bonus, formatted with a dollar sign and two decimal places, in the
bonusLabel. The procedure should not make any calculations when the
salesTextBox is empty; rather, it should display an appropriate message in a
message box. Code the procedure.
c. Save the solution and then start and test the application. Close the solution.
Explanation / Answer
'note: place the functions properly in your project folder to ensure
'correct execution
' Bonus Solution.vb
Module BonusSolution
Sub Main()
End Sub
' clicking calcButton
Sub calcButton_Click procedure()
Dim bonus as Double
If salesTextBox.Text <> null
Dim salesAmount As Double
'get the value
salesAmount=val(salesTextBox.Text)
'calculate bonus
If salesAmount>=0 and salesAmount<=3500 Then
bonus=0.01*salesAmount
ElseIf salesAmount>=3501 and salesAmount<=10000 Then
bonus=0.05*salesAmount
ElseIf salesAmount>10000 Then
bonus=0.1*salesAmount
End If
'to format bonus two decimal places
bonus=Format(bonus, “Fixed”)
'Also to format bonus with dollar sign
bonus=Format (6648972.265, "Currency")
'put bonus to display
bonusLabel.text="bonus" & bonus
'error message when salesTextBox is empty
Else
MsgBox("!!!sales Text Box should not be empty")
End If
End Sub
' sales text box should accept only numbers and the Backspace key.
Private Sub salesTextBox_KeyPress(KeyAscii As Integer)
Select Case KeyPress
'check if key pressed is number or backspace
Case Asc("0") To Asc("9"),vbKeyBack
Exit Sub
Case Else
'set the keyascii to 0
KeyAscii = 0
MsgBox("!!!sales Text Box should not allow keys other than backspace and numbers")
End Select
End Sub
End Module
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.