150 likes | 184 Views
Create a Windows-based application to calculate Gross Pay based on hours worked and hourly pay rate. Input controls for Hours Worked and Hourly Pay Rate, process to calculate Gross Pay, and output control for displaying the result.
E N D
Problem • Create a Windows-based application that will calculate the Gross Pay earned for a worker, given the number of hours worked and hourly pay rate.
Problem Solving • Input (controls): • Hours Worked • Hourly Pay Rate • Process (event handling): • Calculate Gross Pay • Gross Pay = hoursWorked * hourlyPayRate • Output (controls): • Gross Pay
Creating the Visual Basic Application • Event Driven Programming • Create the Interface / Window first • Input • Output • Then Code the Application • Process • Event Handing Methods
Creating the Interface • Input • Hours Worked Textbox, Label • Hourly Pay Rate Textbox, Label • Output • Gross Pay Earned Label (title), Label (display info) • Events • Calculate Gross Pay Button • Exit Program Button
Create Your Interface Label Text Box Label Text Box Label Label 2 Buttons
Properties • Form1 • Name = frmWageCalculator • Text = “Wage Calculator” • Label1 • No Need to Rename (Display Only – will not use) • Text = “Number of Hours Worked” • Label2 • No Need to Rename (Display Only) • Text = “Hourly Pay Rate” • Label3 • No Need to Rename (Display Only) • Text = “Gross Pay Earned”
Properties • Textbox1 • Name: txtHoursWorked • Text: <blank> • Textbox2 • Name: txtPayRate • Text: <blank> • Label4 • Name: lblGrossPay (needs name because will will use this label) • Text: <blank> • Autosize: Off • BorderStyle: FixedSingle • Button1 • Name: btnCalculate • Text: “&Calculate Gross Pay” • Button2 • Name: btnExit • Text: “E&xit”
Process – Event Handling • btnCalculate • Button Click Event • Assignment statement • Gets the data from the text field of the txtHoursWorked textbox and the txtPayRate textbox. • Assign the calculation data from the textboxes into the lblGrossPay text field • Val changes the text input from the text box into a number
Event Handling • btnExit • Button Click Event • End
Run & Test Program • Syntax Errors – Language Errors • Caught by the Compiler & Interpreter • Visual Basic – wavy line under problem code • Run-Time Errors • Causes Program to Crash • Logic Errors • Program Runs but gets “Wrong Answer”
Run & Test Program • Must test for expected and unexpected input
Homework • Create a “Multiplication Tables” application. The program should allow the user to input 2 numbers and then display the product of those 2 numbers. (Remember to use the val function)