Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Clearly VB: programming with Microsoft VB 2010 Ch16 - Ex 9 Any guidance is great

ID: 3527190 • Letter: C

Question

Clearly VB: programming with Microsoft VB 2010

Ch16 - Ex 9

Any guidance is greatly appreciated. Thank you.

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

Explanation / Answer

Public Class Form1 Sub Calculate(ByRef currentRead As TextBox, ByRef previousRead As TextBox, ByRef txtCharge As TextBox, ByRef txtGallons As TextBox) 'sub routine that calculates amount due Const rate = 0.00205 'constant rate set to unchangable value Dim Gallons As Double Gallons = CDbl(currentRead.Text) - CDbl(previousRead.Text) txtGallons.Text = Gallons txtCharge.Text = Format(Gallons * rate, "Currency") End Sub Sub Display(ByVal msg As Integer) 'sub routine that displays messages If msg = 1 Then MessageBox.Show("Error: There must be an value for the previous and current readings", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error) ElseIf msg = 2 Then MessageBox.Show("Error: There must be positive values for the previous and current readings", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error) ElseIf msg = 3 Then MessageBox.Show("Error: The current reading must be greater than the previous readings", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Sub Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs) Handles btnCalculate.Click 'event of btnCalculate being clicked If (txtCurrent.Text = Nothing) Or (txtPrevious.Text = Nothing) Then 'If txtCurrent.Text < 0 Or txtPrevious.Text < 0 Then Call Display(1) ' if negative number or blank number was entered, display error msg 1 ElseIf (txtCurrent.Text < 0) Or (txtPrevious.Text < 0) Then Call Display(2) ElseIf CDbl(txtCurrent.Text)
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote