exercise 9 in Chapter 16 clearly visual basics 2010
In this exercise, you code an application that calculates a water bill. The clerk at the water department will enter the current meter reading and the previous meter reading in two text boxes. The application should calculate and display the number of gallons of water used and the total charge for the water. The charge for water is $2.05 per 1000 gallons, or .00205 per gallon. Use two independent Sub procedures: one to make the calculations and the other to display the results. Call both Sub procedures from the
Calculate button’s Click event procedure. Make the calculations only when the current meter reading is greater than or equal to the previous meter reading; otherwise, display an appropriate message in a message box.
Create a Visual Basic Windows application. Use the following names for the solution and project, respectively: Water Bill Solution and Water Bill Project. Save the application in the ClearlyVB2010\Chap16 folder. Change the name of the form file
on your disk to frmMain.vb. If necessary, change the form’s name to frmMain.
Create the interface shown in Figure 16-24 and then code the application. Be sure to code each text box’s KeyPress and TextChanged event procedures. Save the solution and then
start and test the application. Close the Code Editor window and then close the solution.
- Enlarge your form if necessary. In the bottom center area of the form, add a label with the Text property, Designed by, followed by your name.
- Add a button between the Calculate and Exit buttons, with the text “Clear”, and code it to clear the two input text boxes and the output labels.
- c. Put five comment lines at the top of the code page, listing:
'Project Name: Water Bill Project
'Class: CINS 113-nn [section number]
'Programmer: [your name]
'Date: [date last modified]
'Purpose: [1- or 2-line description of program]
- Put brief comments in all sub procedures, explaining what that section does: the button click procedure, the sub procedure for making the calculations, the sub procedure for displaying the results, as well as the Clear button and the Exit button sub procedures.
- Declare the rate of .00205 dollars per gallon as a constant.
- The variables for Current reading, Previous reading and Gallons used should be integers.
- Your message box for invalid input should include these things:
i. The message should include the numbers the user entered, for example: “ERROR: Current reading (2000) cannot be less than Previous reading (3000).” ii. The title bar text should say “Invalid Input”. iii. The message box button should say “OK”.
iv. The message box icon should be the Error icon.
The output for the total charge should be displayed in currency format.
Run the program, entering 8450 as the Current reading, and 6225 as the Previous reading. Click Calculate, then take a screen shot of the form, paste it at the end of this document, and press ENTER twice.
Clear the text boxes, and run the program again, entering 8450 as the Current reading, and 8995 as the Previous reading. Before you click Calculate, take a screen shot of the form, paste it at the end of the document and press ENTER twice.
Then click Calculate. A message box should pop up with an invalid input error message. Take a screen shot of the message box and paste it at the end of this document.