
IST 256
Lab Week 3, Part 1 - September 10, 2008
1. Compute Salary – extending the compute salary program
For this application, you should open Visual Studio and create a new project
named something like ComputeSalary. This new project should be in the same lab
projects folder as usual.
In the initial form, change the text property of the form for the new
ComputeSalary project.
Version 1 – In-class:
In class, an application was developed for a simpler version of the ComputeSalary
program. The application description was:
Write an application that allows the user to type in the number of hours that they
worked in a week. Then they can click on a button to compute the salary for that
week. The salary is computed as follows: if the number of hours per week is less
than or equal to 40, then the pay rate is $10 per hour and otherwise it is $15 per hour.
Display the salary and allow the user to close the application.
In the form design, there was a label with instructions to the user: “Type number of hours
worked” next to a textbox. There was an (initially invisible) label to display the salary.
There were two buttons, one with “Compute Salary” and the other with “Close”.
In the program, there were
- two variables: Hours and Salary, both of type single to allow for decimal numbers.
- code for the Compute Salary button was to get the hours from the textbox. If the hours
were <= 40, then salary was computed as hours * $10 and otherwise the salary was
computed as hours * $15.
- code for the Close button ends the program.
Here is the program:
‘ The ComputeSalary program takes hours worked and computes salary
‘ Programmer: Nancy McCracken
Public Class Form1
' User will type in hours, salary will be computed
Dim Hours, Salary As Single
' Compute the Salary from the number of hours worked
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
' get the hours from the textbox
Hours = CSng(TextBox1.Text)
' if hours <= 40, pay rate is $10 otherwise rate is $15
If Hours <= 40 Then
Salary = Hours * 10.0
Else
Salary = Hours * 15.0