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

How do I not add value to my calculate button everytime I hit calculate. I just

ID: 3757603 • Letter: H

Question

How do I not add value to my calculate button everytime I hit calculate. I just need it calculate the price once not add on each time I hit it.

Modify the case study project from Chapter 4 to use menus and function procedure. Refer to Chapter 4 for project specifications. Use a function procedure t calculate the rental fee based on type of video. The Help menu About option should display a message box with information about the program and the programmer. The Color option should change the background color of the form; the font changes can change the control of your choice.

Here is my code.

Public Class Form1 Public tot As Double Public c As Integer = totalamt Const VHSPrice As Decimal = 1.8 Const VHSNewReleasePrice As Decimal = 2.0 Const DVDPrice As Decimal = 2.5 Const DVDNewReleasePrice As Decimal = 3.0 Public numberofcustomers As Integer Public totalamt As Decimal Public Property PrintForm1 As Object Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click If txtMovieTitle.Text.Length > 0 Then If rbVHS.Checked Or rbDVD.Checked Then Dim rate As Decimal If rbVHS.Checked Then If chkNewRelease.Checked Then rate = VHSNewReleasePrice Else rate = VHSPrice End If Else If chkNewRelease.Checked Then rate = DVDNewReleasePrice Else rate = DVDPrice End If End If If chkMember.Checked Then rate = rate * 0.9 End If 'calculate totals for all customers numberofcustomers = numberofcustomers + 1 totalamt = rate + totalamt Else MessageBox.Show("Error; you must select VHS or DVD", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End If Else MessageBox.Show("Error; please enter movie title", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End If MsgBox("Rental Amount: " & FormatCurrency(totalamt)) End Sub Private Sub btnClearforNextItem_Click(sender As Object, e As EventArgs) Handles btnClearforNextItem.Click txtMovieTitle.Text = "" rbVHS.Checked = False rbDVD.Checked = False chkNewRelease.Checked = False End Sub Private Sub btnOrderComplete_Click(sender As Object, e As EventArgs) Handles btnOrderComplete.Click Dim reply As DialogResult = MessageBox.Show("Do you want to complete the order?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) txtMovieTitle.Text = "" rbVHS.Checked = False rbDVD.Checked = False chkNewRelease.Checked = False chkMember.Checked = False c = c + 1 End Sub Private Sub btnSummary_Click(sender As Object, e As EventArgs) Handles btnSummary.Click 'calculate total rental amounts for all customers MsgBox("Total Customers: " & c & ", Total Amount: " & FormatCurrency(totalamt, 2)) End Sub Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click ' Print the form. PrintForm1.Print() End Sub Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Close() End Sub End Class

Explanation / Answer

In order to have a new value everytime you click on Calculate button, you should define the variable totalamt, just before you are using it for adding it.(in Sub btnCalculate_Click) , after the numberofcustomers have been incremented. This will initiate it as 0 everytime.

'calculate totals for all customers
numberofcustomers = numberofcustomers + 1
//Define this total amount value here
Public totalamt As Decimal=0.0
totalamt = rate + totalamt

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