Open the solution file contained in the VbReloaded2015\\Chap05\\Bonus Solution f
ID: 3810417 • Letter: O
Question
Open the solution file contained in the VbReloaded2015Chap05Bonus Solution folder. (4. 6. 8, 10) a. The user will enter the sales amount as an integer in the sales Text Box, which should accept only numbers and the Backspace key. Code the appropriate event procedure. b. The calcButton_Click procedure should display the salespersons bonus. A 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 bonus Label. The procedure should not make any calculations when the sales Text Box is empty; rather, it should display an appropriate message in a message box. Code the procedure.Explanation / Answer
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
Place the functions properly in your project folder.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.