Phase 1: Design the Form

Create a Windows Application Open Visual Studio. Create a new Visual Basic Windows Application project by completing the following: Click the New Project button on the Standard toolbar; click Windows Classic Desktop in the left pane; select Windows Forms App; name the project by entering Deck Cost Calculator in the Name text box; then click the OK button in the New Project window.

Name the Form In the Solution Explorer pane, right-click Form1.vb and then click Rename. Type frmDecking.vb and then press the ENTER key. Click the Yes button to automatically change the form (Name) in the Properties window.

Change the Size Property In the Properties window, change the Size property to 720, 431.

Change the BackColor Property In the Properties window, change the BackColor property to White.

Change the Text on the Title Bar To change the text on the title bar, click the form, scroll down the Properties window until the Text property is displayed, double-click the right column of the Text property, type Decking Cost Calculator, and then press the ENTER key.

Add a Heading Label Drag a label onto the form and name the label lblHeading. Set the Text property for the Label object to Decking Cost Calculator. Set the font to Goudy Old Style, Bold, 24 points.

Add a Label Drag a second label onto the frmDecking From object and name the label lblSquareFeet. Set the Text property of the label object to Square Footage:. Set the font to Goudy Old Style, Bold, 16 points.

Add a TextBox Object Drag a TextBox object onto the form. Using snap lines, align the top of the TextBox object with the top of the second Label object. Name the TextBox object txtFootage. Change the TextAlign property to Center. Change the font to Goudy Old Style, Bold, 16 points. Reduce the width of the TextBox object to closely resemble the one in Figure 5-79. Center the Label object and the TextBox object horizontally below the title label.

Figure 6-79: see image.

Add a GroupBox Drag a GroupBox object from the Containers category of the Toolbox to the frmDecking Form object. Name the GroupBox grpDeckType. Change the Text property to Decking Type. Set the size of the GroupBox object to 244, 106. Change the BackColor of the GroupBox object to AliceBlue. Center the GroupBox object horizontally below the title label object, and change the font to Goudy Old Style, Regular, 14 points.

Add Radio Buttons Place three RadioButton objects on the GroupBox object. Name the first RadioButton radLumber and change its Text property to Pressure-Treated Lumber. Name the second RadioButton radRedwood and change its Text property to Redwood. Name the third RadioButton radComposite and change its Text property to Composite. If necessary, select the three RadioButtons and change the font to Goudy Old Style, Regular, 14 points.

Add Estimate and Cost Labels Drag two more Label objects onto the form below the GroupBox object. Align these labels by their tops using snap lines. Name the first label lblCost, change its Text property to Cost Estimate:, and resize the Label object to view the text. Name the second label lblCostEstimate and set its Text property to $0000.00. These placement zeros allow you to view the Label object when it is not selected. The placement zeros will be cleared using code when the form is loaded. Change the font for both Label objects to Goudy Old Style, Bold, 16 points. Horizontally center the labels as a unit below the title label.

Add Calculate and Clear Buttons Drag two Button objects onto the form. Align the tops of the Button objects using snap lines. Name the left Button object btnCalculate and change its Text property to Calculate. Name the right Button object btnClear and change its Text property to Clear. Change the font for these two buttons to Goudy Old Style, Bold, 14 points. Change the size of each button to 116, 41. Change the BackColor property for each button to White.

Change the ForeColor Property Select every object and change the ForeColor property to Sienna.

Add a Picture to the Windows Form Download the deck.jpg picture by visiting CengageBrain.com and accessing the resources for this chapter. Drag a PictureBox object to the right side of the Windows Form. Name the picture picDeck. Change the Size property of the PictureBox object to 338, 390. Change the SizeMode property to StretchImage.

Phase 2: Code the Application

Code the Comments Double-click the btnCalculate Button object on the frmDecking Form object to open the code window and create the btnCalculate_Click event handler. Close the Toolbox. Click before the firt words, Public Class frmDecking, and then press the ENTER key to create a blank line. Insert the first four standard comments. Insert the Option Strict On command at the beginning of the code to turn on strict-type checking.

Add Comments to the btnCalculate_Click Event Handler Enter a comment to describe the purpose of the btnCalculate_Click event.

Declare and Initialize the Variables This application requires six Decimal variables: (1) decFootage: Holds the estimated square footage of the decking; (2) decCostPerSquareFoot: Holds the cost per square foot based on the decking type; (3) decCostEstimate: Is assigned the calculated final estimated cost; (4) decLumberCost: Is assigned the value 2.35; (5) decRedwoodCost: Is assigned the value 7.75; (6) decCompositeCost: Is assigned the value 8.50. Declare and initialize these six variables.

Write the If Statement to Test for Numeric Data When the user clicks the Calculate button, the program must first ensure that the user entered a valid numeric value in the txtFootage TextBox object. If the user has entered a valid numeric value, the value must be converted from a string value into a Decimal data type. Write the If statement and conversion statement required for this process.

Write the If Statement to Test for a Positive Number If the value in the txtFootage TextBox object is numeric, then the converted numeric value must be checked to ensure that it is a positive number. Write the If statement to check whether the converted numeric value is greater than zero.

Write the If Statement to Determine the Cost Per Square Foot When the value is greater than zero, the cost per square foot is determined by checking the status of the RadioButton objects and placing the appropriate cost per square foot in the decCostPerSquareFoot variable. Using the If Then ElseIf structure, write the statements to identify the checked radio button and place appropriate cost in the decCostPerSquareFoot variable.

Calculate and Display the Cost Estimate The next step is to calculate the cost estimate by multiplying the value in the decCostPerSquareFoot variable by the square footage. Next, display the cost estimate in the cost estimate label. Write the statements to calculate and display the cost estimate in the currency format.

Display a Message Box If the Value Entered Is Not Greater Than Zero After the processing is finished for the true portion of the If statements, the Else portion of the If statements must be written. Write the code to display the message box that contains the error message when the user enters a value that is not greater than zero.

Display an Error Message If the Value Entered Is Not Numeric Write the Else potion of the If statement to display an error message if the value entered by the user is not numeric.

Create the Clear Button Click Event Handler The Clear button click event includes the following processing: (1) clear the txtFootage Text property; (2) clear the lblCostEstimate Text property; (3) set the radLumber Checked property to True; (4) set the radRedWood and radComposite Checked properties to False; (5) set the focus in the txtFootage text box. To enter this code, click the frmDecking.vb [Design] tab and then double-click the Clear button. Using IntelliSense, enter the required code.

Create the Form Load Event Handler When the frmDecking Form object loads, the following processing should occur: (1) the focus is in the txtFootage text box; (2) the lblCostEstimate Text property is set to null. Click the frmDecking.vb [Design] tab to return to Design view and then double-click the form. Enter the code for the form load event handler.

Run the Application After you have completed the code, you should run the application to ensure that it works properly.

Test the Application Test the application with the following data: (1) square footage 250, decking type Pressure-Treated Lumber; (2) square footage 210, decking type Composite; (3) square footage 170, decking type Redwood; (4) square footage Fifteen (use this word), decking type Composite; (5) square footage -800, decking type Pressure-Treated Lumber; (6) use other values to thoroughly test the program. After each test, click the Clear button before entering new data.

Close the Program After testing the application, close the window by clicking the Close button in the title bar of the window.

Questions

Provide examples for each case listed below on how would you use:

  • If then statement in a program.
  • If then else if statement in a program.
  • Nested if statement in a program.
  • How would you write code to determine the choice made by the user from a drop down box.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.