Very Busy (VB) Mail Order
Part one is a review from last week on how to complete the first step of every project
Start Visual Basic and Open a New Standard .EXE
Do the housekeeping required to setup your project. This includes:
- Creating a New Project Directory
- Saving the Form
- Saving the Project File
Refer to the Guidelines for this procedure and for the required naming conventions.
Specifications
Calculate employee bonus pay for the month. Bonus is based on sales and on hours worked for the store for the month. The employee bonus is 2% of total store sales, but prorated based on the percentage of hours actually worked.
User Interface
Reviewing the problem reveals that the user interface will need these considerations:
Text Boxes to accept input for Name, Hours Worked, and Sales Amount. You must maintain the proper Label - Text Box association for the keyboard interface. Command Buttons to Calculate, Clear, Print the form and Exit the program. Set the appropriate properties for the proper keyboard interface including default/cancel implementation. Use of a frame makes for a nicer user interface and allows you to move the group of controls when "fine tuning" is needed.
Disabling the Print button when no employee bonus has been calculated will prevent accidental printing of an incomplete form. Be sure to enable the button after the bonus has been calculated, and to again disable the button when the form controls have been cleared. Clearing the form should clear all the form controls and reset the cursor to the proper starting location.
The coding is detailed below for the Calculate button as the coding of the other three is trivial.
' Use constants for Hours and Bonus Rate
Const intHoursPerMonth As Integer = 160
Const sngBonusPct As Single = 0.02
'Calculate the bonus earned by each employee
Dim sngSales As Single
Dim sngHours As Single
Dim sngBonus As Single
sngSales = Val(txtSales.Text)
sngHours = Val(txtHours.Text)
sngBonus = sngSales * (sngHours / intHoursPerMonth) * sngBonusPct
lblBonus.Caption = FormatCurrency(sngBonus)
cmdPrint.Enabled = True
Test the program using test data for which you know what the results should be.
Just because you get results does not mean that the results are correct
A couple of things to double check:
This completes the lab