Speaker Notes to Accompany
This is a simple pay project. Note that in this project, I am covering information not covered in the first chapter in your text. You will need to read the slides carefully and use your text for reference.
Note that you save the project as a .vbp and the form as a .frm. I will show the pulldown on the next slide. In this example the name that I gave to the project is not the same as the name that I saved it as. Think before you do this because it can be hard to remember the name if it is named one thing and saved as something else.
This shows the naming of the form and the save that was done using the same name with the .frm extension.
The form is named frmPay1. Note the background color that is specified for the form.
The label across the top is done in blue and other things are changed to Blue and to size 12.
All of the labels and testboxes were set up with names and defined using mostly standard defaults. In the case of the labels the caption was changed and in the case of the testboxes the text was changed.
When the calculate button is pressed, the Pay is calculated by multiplying the pay per hour by the hours worked. Note that both are converted to Val prior to doing the calculation. Note also that I am using the .Text on all textbox fields. Since Text is the default property, it is not required.
Val is used to make sure that the data is numeric. Val is a function that converts text to numeric.
Note also that the exit button simply gives the command End.
I left the code on the screen so that it shows what happens when the calculate button is clicked. This time I did Run and then clicked the Calculate button. Note that I had entered social security number, name, pay per hour and hours. Because I clicked the Calculate button, Pay was calculated and placed in txtPay.text.
In this example, I defined work areas as wrkPayHr, wrkHours and wrkPay. Note that this is done with the Dim statement which names the field and gives each a type. In this case, I selected Single which allows for basic decimal places. Please look up the definition of single in the textbook or help.
I then assigned the payper hour and the hours worked to the work areas that I defined. This takes the data that was entered into the text boxes and puts the data into work areas.
I then did the calculation of multiplying them together and stored the answer in the work area. I then displayed the pay per hour and the calculated pay in the boxes using the currency format. Note that the place to display is on the left and the calculation to format the work area as currency is placed on the right. The assignment sign takes what is on the right and assigns it to the field on the left.
The Format command can take data and format it using one of the Visual Basic formatting styles. In this case I am saying Format wrkPayHr as currency and store it in txtPayHr.Text. I am also saying Format wrkPay as currency and store it in txtPay.Text. The results will be leading dollar signs and commas if needed.
When the Calculate button is pressed the data is stored in the work areas using the commands wrkPayHr = Val(txtPayHr.Text) and wrkHours = Val(txtHours.Text). Then the calculation is done by the command wrkPay = wrkPayHr * wrkHours. Note that the calculate works exculsively with work areas in this eample. Finally the formatting is done and the results are displayed. You can see that txtPayHr.Text and txtPay.Text both contain data that was formatted as currency.