www hndit com HNDIT 23073 Rapid Application Development

  • Slides: 20
Download presentation
www. hndit. com HNDIT 23073 Rapid Application Development Week 2 - Developing a Visual

www. hndit. com HNDIT 23073 Rapid Application Development Week 2 - Developing a Visual Basic Application

www. hndit. com Problem • Create a Windows-based application that will calculate the Gross

www. hndit. com 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.

www. hndit. com Step 1: Understand Problem • Clearly define the problem and identify

www. hndit. com Step 1: Understand Problem • Clearly define the problem and identify what the program is to do – Purpose: To calculate a worker’s gross pay – Input: Number of hours worked, hourly pay rate – Process: Multiply number of hours worked by hourly pay rate (result is the user’s gross pay) – Output: Display a message indicating the user’s gross pay

www. hndit. com Step 2: Design Solution Traditional Procedural Approach - Develop an algorithm:

www. hndit. com Step 2: Design Solution Traditional Procedural Approach - Develop an algorithm: • • Display message: "How many hours did you work? " Allow user to enter number of hours worked Store the number the user enters in memory Display message: "How much are you paid per hour? " Allow the user to enter an hourly pay rate Store the number the user enters in memory Multiply hours worked by pay rate and store the result in memory Display a message with the result of the previous step This well-defined, ordered set of steps for solving a problem is called an algorithm.

www. hndit. com Step 2: Design Solution (cont. ) VB (GUI) Approach – Identify

www. hndit. com Step 2: Design Solution (cont. ) VB (GUI) Approach – Identify required controls and events/handlers • Inputs - entered into the program via Controls: – Hours Worked – Hourly Pay Rate • Processes - initiated by Events and carried out by the code contained in the corresponding Event Procedures: – Calculate Gross Pay • Gross Pay = hours. Worked * hourly. Pay. Rate • Output - displayed to the user via Controls: – Gross Pay

www. hndit. com Step 2: Design Solution (cont. ) • Inputs (controls): – Hours

www. hndit. com Step 2: Design Solution (cont. ) • Inputs (controls): – Hours Worked Textbox, Label (title/prompt) – Hourly Pay Rate Textbox, Label (title/prompt) • Processes (events/event procedures): – Calculate Gross Pay Button(click) • Gross Pay = hours. Worked * hourly. Pay. Rate – Exit Program Button(click) • End • Outputs (controls): – Gross Pay Earned Label (display result), Label (title)

www. hndit. com Step 2: Design Solution (cont. ) Design the Interface – TOE

www. hndit. com Step 2: Design Solution (cont. ) Design the Interface – TOE Chart • Task, Object, Event • Plan the interface BEFORE creating in VB • Examines all of the tasks involved in solution Task (T) Object (O) Event (E) Input Hours Worked Textbox, Label None Input Pay Rate Textbox, Label None Output Gross Pay Label (display), Label (title) None Calculate Gross Pay Button Click Exit Program Button Click

www. hndit. com Step 2: Design Solution (cont. ) • Make a list of

www. hndit. com Step 2: Design Solution (cont. ) • Make a list of the controls needed • Define values for each control's relevant properties: Control Type Form Text. Box Label Button Control Name (Default) txt. Hours. Worked (Default) txt. Pay. Rate (Default) lbl. Gross. Pay (Default) btn. Calc. Gross. Pay btn. Exit Text "Wage Calculator" "" "Number of Hours Worked" "" "Hourly Pay Rate" "$0. 00" "Gross Pay Earned" "Calculate Gross Pay" “Exit"

www. hndit. com Step 2: Design Solution (cont. ) • Make a list the

www. hndit. com Step 2: Design Solution (cont. ) • Make a list the events/procedures needed • Develop an algorithm for each procedure Event Procedure Code Algorithm btn. Calc. Gross. Pay_Click Get hours worked from txt. Hours. Worked Get hourly pay rate from txt. Pay. Rate Multiply hours worked by hourly pay rate Assign result to lbl. Gross. Pay btn. Close_Click End the application

www. hndit. com Step 2: Design Solution (cont. ) • Visualize the application running

www. hndit. com Step 2: Design Solution (cont. ) • Visualize the application running on the computer and design its user interface

www. hndit. com Step 3: Implementation • Creating the Visual Basic Application - Event

www. hndit. com Step 3: Implementation • Creating the Visual Basic Application - Event Driven Programming Steps – Create the Interface / Window first • Input • Output – Set the Properties • Configure the appearance and behavior of the controls – Then Code the Application • Processes - Event Handing Methods

www. hndit. com Step 3: Implementation(cont. ) • Create the Interface - Use Visual

www. hndit. com Step 3: Implementation(cont. ) • Create the Interface - Use Visual Basic to create the forms and other controls identified in the previous step – This is the first use of Visual Basic, all of the previous steps have just been on paper – In this step you develop the portion of the application the user will see Label 2 Buttons Text Box Label

www. hndit. com Step 3: Implementation(cont. ) • Set Properties - Use Visual Basic

www. hndit. com Step 3: Implementation(cont. ) • Set Properties - Use Visual Basic to set properties for the forms and other controls from list you made earlier – In this step you still developing the portion of the application the user will see Control Type Form Text. Box Label Button Control Name (Default) txt. Hours. Worked (Default) txt. Pay. Rate (Default) lbl. Gross. Pay (Default) btn. Calc. Gross. Pay btn. Exit Text "Wage Calculator" "" "Number of Hours Worked" "" "Hourly Pay Rate" "$0. 00" "Gross Pay Earned" "Calculate Gross Pay" “Exit"

www. hndit. com Step 3: Implementation(cont. ) • Create the Events/Procedures - Use Visual

www. hndit. com Step 3: Implementation(cont. ) • Create the Events/Procedures - Use Visual Basic to create and write the code for the event procedures identified earlier – In this step you develop the methods behind the click event for each button – Unlike the interface, this portion of the application is invisible to the user

www. hndit. com Step 3: Implementation(cont. ) �btn. Calculate Button Click Event Assignment statement

www. hndit. com Step 3: Implementation(cont. ) �btn. Calculate Button Click Event Assignment statement lbl. Gross. Pay. text = Val(txt. Hours. Worked. text) * Val(txt. Pay. Rate. text) ▪ Gets data from txt. Hours. Worked. text and txt. Pay. Rate. text ▪ Assigns results from hours * rate calculation to lbl. Gross. Pay. text Val changes the text input from the text box into a number

www. hndit. com Step 3: Implementation(cont. ) • btn. Exit – Button Click Event

www. hndit. com Step 3: Implementation(cont. ) • btn. Exit – Button Click Event – End

www. hndit. com Step 4: Evaluation 3 Major Types of Errors • Syntax Errors

www. hndit. com Step 4: Evaluation 3 Major Types of Errors • Syntax Errors – Language Errors – Caught by the Compiler & Interpreter – Visual Basic – wavy line under problem code • Run-Time Errors – Program will not run to normal completion – Program Crashes • Logic Errors – Program Runs but produces incorrect results

www. hndit. com Step 4: Evaluation(cont. ) • Attempt to run the application -

www. hndit. com Step 4: Evaluation(cont. ) • Attempt to run the application - find syntax errors and runtime errors – Correct any syntax errors found – indicated by wavy blue line – All syntax errors must be removed before Visual Basic will create a program that actually runs – Find and correct any runtime errors until program runs to normal completion

www. hndit. com Step 4: Evaluation(cont. ) • Run the application using test data

www. hndit. com Step 4: Evaluation(cont. ) • Run the application using test data as input – Run the program with a variety of test data – Must test for expected and unexpected input • negative numbers, blank text box, etc. • will talk about how to deal with invalid input later – Check the results to be sure that they are correct – Correct any logic errors found – Repeat this step as many times as necessary

www. hndit. com Reference • http: //www. cis. usouthal. edu, 2014/03/10

www. hndit. com Reference • http: //www. cis. usouthal. edu, 2014/03/10