none
Can't Figure This Out Not accumulating RRS feed

  • Question

  • Im a student currently learning Visual Basic. I have coded and made this application for a "salon" offers 4 choices (buttons) Haircut, pedicure, manicure and facial. all with separate prices and it should have a accumulating total so that when haircut is chosen then manicure the subtotal and tax boxes should adjust to the new price. I have the Total correct it adds up correctly when all boxes are chosen where as the subtotal boxes and tax box only show the amount for the individual selection. I can not figure out why the total adds up correctly but the subtotal and tax doesnt. 
    Option Strict On
    Public Class frmSalonSpa
    
        Const _cDecTax As Decimal = 0.07D
        Const _cDecCostOfFacial As Decimal = 8D
        Const _cDecCostOfPedicure As Decimal = 15D
        Const _cDecCostOfManicure As Decimal = 10D
        Const _cDecCostOfHaircut As Decimal = 5D
    
        Dim _cDecTax2 As Decimal = 0
        Dim _cDecTotal As Decimal = 0
        Dim _cDecSubTotal As Decimal = 0
        Private Const V As Decimal = 0
    
    
    
    
        Private Sub btnHaircut_Click(sender As Object, e As EventArgs) Handles btnHaircut.Click
           
            _cDecSubTotal = _cDecCostOfHaircut + _cDecSubTotal
            lblSubtotal.Text = _cDecSubTotal.ToString("C2")          
            lblSubtotal.Text = _cDecCostOfHaircut.ToString("C2")    
    
            _cDecTax2 = _cDecTax * _cDecCostOfHaircut
            lblTax.Text = _cDecTax2.ToString("C2")
            lblTax.Text = _cDecTax2.ToString("C2")
    
            _cDecTotal = _cDecTax2 + _cDecSubTotal                 
            lblTotal.Text = _cDecCostOfHaircut.ToString("C2")        
            lblTotal.Text = _cDecTotal.ToString("C2")
    
    
            btnHaircut.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True
    
    
    
        End Sub
    
        Private Sub btnManicure_Click(sender As Object, e As EventArgs) Handles btnManicure.Click
            
    
            _cDecSubTotal = _cDecCostOfManicure + _cDecSubTotal 
            _cDecTax2 = _cDecTax * _cDecCostOfManicure          
            _cDecTotal = _cDecTax + _cDecSubTotal                 
    
            lblSubtotal.Text = _cDecSubTotal.ToString("C2")            
            lblSubtotal.Text = _cDecCostOfManicure.ToString("C2")     
            lblTotal.Text = _cDecCostOfManicure.ToString("C2")        
    
    
            lblTotal.Text = _cDecTotal.ToString("C2")
            lblTax.Text = _cDecTax2.ToString("C2")
    
    
    
    
    
            btnManicure.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True
    
        End Sub
    
        Private Sub btnPedicure_Click(sender As Object, e As EventArgs) Handles btnPedicure.Click
            
    
            _cDecSubTotal = _cDecCostOfPedicure + _cDecSubTotal  
            _cDecTax2 = _cDecTax * _cDecCostOfPedicure          
            _cDecTotal = _cDecTax2 + _cDecSubTotal                 
    
            lblSubtotal.Text = _cDecSubTotal.ToString("C2")            
            lblSubtotal.Text = _cDecCostOfPedicure.ToString("C2")     
            lblTotal.Text = _cDecCostOfPedicure.ToString("C2")        
    
    
            lblTotal.Text = _cDecTotal.ToString("C2")
            lblTax.Text = _cDecTax2.ToString("C2")
    
    
            btnPedicure.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True
    
    
        End Sub
    
        Private Sub btnFacial_Click(sender As Object, e As EventArgs) Handles btnFacial.Click
          
    
            _cDecSubTotal = _cDecCostOfFacial + _cDecSubTotal  
            _cDecTax2 = _cDecTax * _cDecCostOfFacial          
            _cDecTotal = _cDecTax2 + _cDecSubTotal                 
    
            lblSubtotal.Text = _cDecSubTotal.ToString("C2")            
            lblSubtotal.Text = _cDecCostOfFacial.ToString("C2")     
            lblTotal.Text = _cDecCostOfFacial.ToString("C2")        
    
    
            lblTotal.Text = _cDecTotal.ToString("C2")
            lblTax.Text = _cDecTax2.ToString("C2")
    
    
            btnFacial.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True
    
        End Sub
    
        Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
            ' This code resets the selected buttons
    
            btnHaircut.Enabled = True
            btnManicure.Enabled = True
            btnPedicure.Enabled = True
            btnFacial.Enabled = True
            btnReset.Enabled = False
            btnMakeAppointment.Enabled = False
    
            lblTotal.Text = CType(V, String)
            lblSubtotal.Text = CType(V, String)
            lblTax.Text = CType(V, String)
    
        End Sub
    
        Private Sub btnMakeAppointment_Click(sender As Object, e As EventArgs) Handles btnMakeAppointment.Click
            ' This code resets the choices and we assume that the appointent is made.
    
    
    
            btnHaircut.Enabled = True
            btnManicure.Enabled = True
            btnPedicure.Enabled = True
            btnFacial.Enabled = True
            btnReset.Enabled = False
            btnMakeAppointment.Enabled = False
    
            lblTotal.Text = CType(V, String)
            lblSubtotal.Text = CType(V, String)
            lblTax.Text = CType(V, String)
    
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
    
        End Sub



    • Edited by Willdthrill Thursday, March 7, 2019 8:49 PM
    Thursday, March 7, 2019 7:19 PM

All replies

  • so I have to make an application that has four selections, that each has an individual price. I need the subtotal, tax and Total to appear and increase as the other selections are chosen. I have figured out the code for displaying the correct price in the correct locations for each button, but the problem is when a new one is selected the values do not add they are replaced with the new selections prices
    • Edited by Willdthrill Tuesday, March 5, 2019 11:21 PM
    • Merged by Alex Li-MSFT Wednesday, March 27, 2019 7:54 AM same case
    Tuesday, March 5, 2019 11:18 PM
  • Hi

    You will need to show the code you have so far.


    Regards Les, Livingston, Scotland

    Tuesday, March 5, 2019 11:32 PM
  •   Private Sub btnHaircut_Click(sender As Object, e As EventArgs) Handles btnHaircut.Click

            Dim decTax As Decimal
            Dim decTotal As Decimal
            Dim decSubTotal As Decimal



            decSubTotal = _cDecCostOfHaircut + decSubTotal
            decTax = _cDecTax * _cDecCostOfHaircut          
            decTotal = decTax + decSubTotal                 

            lblSubtotal.Text = decSubTotal.ToString("C") 

            lblSubtotal.Text = _cDecCostOfHaircut.ToString("C")  

            lblTotal.Text = _cDecCostOfHaircut.ToString("C")     

            lblTotal.Text = decTotal.ToString("C")
            lblTax.Text = decTax.ToString("C")



            btnHaircut.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True



        End Sub

            
    Wednesday, March 6, 2019 1:51 PM
  • I have the same code in place for the other selections the 4 selections are haircut, pedicure manicure, and facial. I changed the names to the appropriate ones in the code. it displays the correct subtotal and tax and total per item problem is that when a new button is clicked the values arent adding the new selections price displays 
    • Edited by Willdthrill Wednesday, March 6, 2019 2:22 PM
    Wednesday, March 6, 2019 2:18 PM
  • To maintain existing contents it is often sufficient to declare the variable
    as Static. For example consider a button click event such as this:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim total As Integer = 0
        total += 12
        TextBox1.Text = total.ToString
    End Sub
    

    Each time the button is pressed 12 will be added to total. But because total
    is not static, every time the button is pressed the textbox will always show
    12. However if you make total Static:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Static Dim total As Integer = 0
        total += 12
        TextBox1.Text = total.ToString
    End Sub
    

    then each time the button is pressed total will increase by 12 and the textbox
    will show 12 then 24 then 36, etc.

    - Wayne

    Wednesday, March 6, 2019 2:55 PM
  • I have the same code in place for the other selections the 4 selections are haircut, pedicure manicure, and facial. I changed the names to the appropriate ones in the code. it displays the correct subtotal and tax and total per item problem is that when a new button is clicked the values arent adding the new selections price displays 

    Hi

    There is no way I can figure out the different Forms you may have, but, from the information gleaned so far, here is one possibility. This is a stand alone example and if you want to try it out, start a new default Project, layout the controls in the Designer (use default control names), and copy/replace all of the Form1 code with the code below.

    I have kept everything on one Form, you may have other ideas there. There is one Tax rate applied to overall costs to produce the end Total cost.

    The boxes containing calculated values are ReadOnly so User can't change them. The basic costs are set at top of code for the different products, but these value are editable on the Form.

    The calculations are dynamic - meaning that when you change an input box, the Total is recalculated 'on the fly' so to speak.

    The Appointments Button does nothing in this example. The Reset Button does just that.

    If User enters anything that is not a valid Decimal number then the input is ignore/corrected (to zero value).

    The default produce values are entered into boxes on checkbox checked (and cleared on unchecking)

    Bear in mind that this is just an example.

    Image

    Code

    ' Form1 with TextBoxes x 7, Button1
    ' and Button2 (plus informative
    ' Labels)
    Option Strict On
    Option Explicit On
    Public Class Form1
    
      ' set these default values here
      ' default haircut cost
      Dim _cDecCostOfHaircut As Decimal = 12.33D
      Dim _cDecCostOfPedicure As Decimal = 112D
      Dim _cDecCostOfManicure As Decimal = 15.5D
      Dim _cDecCostOfFacial As Decimal = 18.75D
    
      ' default Tax rate as a percentage
      Dim _cDecTax As Decimal = 7.5D
    
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' these are calculated values
        TextBox6.ReadOnly = True
        TextBox7.ReadOnly = True
        ' set default values
      End Sub
    
      Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        TextBox1.Text = "0.00"
        TextBox2.Text = "0.00"
        TextBox3.Text = "0.00"
        TextBox4.Text = "0.00"
    
        SetDefaults()
    
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ' RESET
        SetDefaults()
      End Sub
      Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        ' MAKE APPOINTMENT HERE
    
      End Sub
      Sub SetDefaults()
    
        CheckBox1.Checked = False
        CheckBox2.Checked = False
        CheckBox3.Checked = False
        CheckBox4.Checked = False
    
        ' show Tax rate
        TextBox5.Text = _cDecTax.ToString("0.0")
      End Sub
      Private Sub TextBox_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged, TextBox4.TextChanged, TextBox5.TextChanged
        ' Update totals when input
        ' values are changed
        Dim hc As Decimal = GetDecimal(TextBox1.Text) + GetDecimal(TextBox2.Text) + GetDecimal(TextBox3.Text) + GetDecimal(TextBox4.Text)
        Dim Tax As Decimal = GetDecimal(TextBox5.Text)
        TextBox6.Text = (hc / 100 * Tax).ToString("0.00")
        TextBox7.Text = (hc + hc / 100 * Tax).ToString("0.00")
      End Sub
      Private Sub TextBox_Validated(sender As Object, e As EventArgs) Handles TextBox1.Validated, TextBox2.Validated, TextBox3.Validated
        ' keep currency display
        TextBox1.Text = GetDecimal(TextBox1.Text).ToString("0.00")
        TextBox2.Text = GetDecimal(TextBox2.Text).ToString("0.00")
        TextBox3.Text = GetDecimal(TextBox3.Text).ToString("0.00")
      End Sub
      Function GetDecimal(s As String) As Decimal
        ' ensure values are valid
        ' Decimal numbers
        Dim d As Decimal = 0D
        If Decimal.TryParse(s, d) Then Return d
        Return 0D
      End Function
      Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        ' Haircut
        Select Case CheckBox1.Checked
          Case True
            TextBox1.Text = _cDecCostOfHaircut.ToString("0.00")
          Case Else
            TextBox1.Text = "0.00"
        End Select
      End Sub
      Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
        ' Pedicure
        Select Case CheckBox2.Checked
          Case True
            TextBox2.Text = _cDecCostOfPedicure.ToString("0.00")
          Case Else
            TextBox2.Text = "0.00"
        End Select
      End Sub
      Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox3.CheckedChanged
        ' Manicure
        Select Case CheckBox3.Checked
          Case True
            TextBox3.Text = _cDecCostOfManicure.ToString("0.00")
          Case Else
            TextBox3.Text = "0.00"
        End Select
      End Sub
      Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox4.CheckedChanged
        ' Facial
        Select Case CheckBox4.Checked
          Case True
            TextBox4.Text = _cDecCostOfFacial.ToString("0.00")
          Case Else
            TextBox4.Text = "0.00"
        End Select
      End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, March 6, 2019 4:13 PM
    Wednesday, March 6, 2019 4:11 PM
  • This is my full code

    Option Strict On
    Public Class frmSalonSpa
    
        Const _cDecTax As Decimal = 0.07D
        Const _cDecCostOfFacial As Decimal = 8D
        Const _cDecCostOfPedicure As Decimal = 15D
        Const _cDecCostOfManicure As Decimal = 10D
        Const _cDecCostOfHaircut As Decimal = 5D
    
        Private Const V As Double = 0.00
    
        Private Sub btnHaircut_Click(sender As Object, e As EventArgs) Handles btnHaircut.Click
    
    
            Dim decTax As Decimal
            Dim decTotal As Decimal
            Dim decSubTotal As Decimal
    
    
    
            decSubTotal = _cDecCostOfHaircut + decSubTotal
            decTax = _cDecTax * _cDecCostOfHaircut          
            decTotal = decTax + decSubTotal                 
    
    
            lblSubtotal.Text = decSubTotal.ToString("C") 
            lblSubtotal.Text = _cDecCostOfHaircut.ToString("C")
    
           lblTotal.Text = _cDecCostOfHaircut.ToString("C") 
    
    
            lblTotal.Text = decTotal.ToString("C")
            lblTax.Text = decTax.ToString("C")
    
    
            btnHaircut.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True
    
    
    
        End Sub
    
        Private Sub btnManicure_Click(sender As Object, e As EventArgs) Handles btnManicure.Click
        
    
            Dim decTax As Decimal
            Dim decTotal As Decimal
            Dim decSubTotal As Decimal
    
    
    
            decSubTotal = _cDecCostOfManicure + decSubTotal 
            decTax = _cDecTax * _cDecCostOfManicure          
            decTotal = decTax + decSubTotal                 
    
            lblSubtotal.Text = decSubTotal.ToString("C")          
            lblSubtotal.Text = _cDecCostOfManicure.ToString("C")   
            lblTotal.Text = _cDecCostOfManicure.ToString("C")        
    
    
            lblTotal.Text = decTotal.ToString("C")
            lblTax.Text = decTax.ToString("C")
    
    
    
    
    
            btnManicure.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True
    
        End Sub
    
        Private Sub btnPedicure_Click(sender As Object, e As EventArgs) Handles btnPedicure.Click
          
    
            Dim decTax As Decimal
            Dim decTotal As Decimal
            Dim decSubTotal As Decimal
    
    
    
            decSubTotal = _cDecCostOfPedicure + decSubTotal  
            decTax = _cDecTax * _cDecCostOfPedicure          
            decTotal = decTax + decSubTotal                 
    
            lblSubtotal.Text = decSubTotal.ToString("C") 
            lblSubtotal.Text = _cDecCostOfPedicure.ToString("C")
            lblTotal.Text = _cDecCostOfPedicure.ToString("C")     
    
    
            lblTotal.Text = decTotal.ToString("C")
            lblTax.Text = decTax.ToString("C")
    
    
            btnPedicure.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True
    
    
        End Sub
    
        Private Sub btnFacial_Click(sender As Object, e As EventArgs) Handles btnFacial.Click
           
    
    
            Dim decTax As Decimal
            Dim decTotal As Decimal
            Dim decSubTotal As Decimal
    
    
    
            decSubTotal = _cDecCostOfFacial + decSubTotal  
            decTax = _cDecTax * _cDecCostOfFacial          
            decTotal = decTax + decSubTotal                
    
            lblSubtotal.Text = decSubTotal.ToString("C")           
            lblSubtotal.Text = _cDecCostOfFacial.ToString("C")    
            lblTotal.Text = _cDecCostOfFacial.ToString("C")      
    
    
            lblTotal.Text = decTotal.ToString("C")
            lblTax.Text = decTax.ToString("C")
    
    
            btnFacial.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True
    
        End Sub
    
        Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
            
    
            btnHaircut.Enabled = True
            btnManicure.Enabled = True
            btnPedicure.Enabled = True
            btnFacial.Enabled = True
            btnReset.Enabled = False
            btnMakeAppointment.Enabled = False
    
            lblTotal.Text = CType(V, String)
            lblSubtotal.Text = CType(V, String)
            lblTax.Text = CType(V, String)
    
        End Sub
    
        Private Sub btnMakeAppointment_Click(sender As Object, e As EventArgs) Handles btnMakeAppointment.Click
           
    
    
            btnHaircut.Enabled = True
            btnManicure.Enabled = True
            btnPedicure.Enabled = True
            btnFacial.Enabled = True
            btnReset.Enabled = False
            btnMakeAppointment.Enabled = False
    
            lblTotal.Text = CType(V, String)
            lblSubtotal.Text = CType(V, String)
            lblTax.Text = CType(V, String)
    
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
    
        End Sub
    End Class
    


    Wednesday, March 6, 2019 4:32 PM
  • Hi

    When posting code, please use the Code Block tool - available on the toolbar.

    Did you try the example I posted?


    Regards Les, Livingston, Scotland

    Wednesday, March 6, 2019 4:40 PM
  • i didnt see it before posting my code sorry about that. Im not using text boxes or check boxes. so im not sure how i would apply it to what i have. Sorry about my lack of knowledge this is my first class on programming, Ive just been stuck on this for a few weeks.
    Wednesday, March 6, 2019 4:46 PM
  • Hi

    Ah OK, a student assignment. You should have mentioned that.

    The code I posted is a complete new Project. You just need to add the controls as seen in the Image in the Designer and copy/replace all the default Form1 code with the code I posted.

    The TextBoxes are TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6 and TextBox7. In other words, the default names that you will get when dragging each TextBox from the Toolbox onto the Form. The CheckBoxes are 1-4, again, the default names you will get as you add them. Once you have all the controls on the Form, then copy the code I posted and Paste it over the default code for Form1.

    Give it a try. I wouldn't expect it to be as you need it, but, it should help in givimg you ideas etc.


    Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, March 6, 2019 5:04 PM
    Wednesday, March 6, 2019 5:03 PM
  • This is my full code

    Option Strict On
    Public Class frmSalonSpa
    
        Const _cDecTax As Decimal = 0.07D
        Const _cDecCostOfFacial As Decimal = 8D
        Const _cDecCostOfPedicure As Decimal = 15D
        Const _cDecCostOfManicure As Decimal = 10D
        Const _cDecCostOfHaircut As Decimal = 5D
    
        Private Const V As Double = 0.00
    
        Private Sub btnHaircut_Click(sender As Object, e As EventArgs) Handles btnHaircut.Click
    
    
            Dim decTax As Decimal
            Dim decTotal As Decimal
            Dim decSubTotal As Decimal
    
    
    
            decSubTotal = _cDecCostOfHaircut + decSubTotal
            decTax = _cDecTax * _cDecCostOfHaircut          
            decTotal = decTax + decSubTotal                 
    
    
        Private Sub btnManicure_Click(sender As Object, e As EventArgs) Handles btnManicure.Click
        
    
            Dim decTax As Decimal
            Dim decTotal As Decimal
            Dim decSubTotal As Decimal
    
    
    
            decSubTotal = _cDecCostOfManicure + decSubTotal 
            decTax = _cDecTax * _cDecCostOfManicure          
            decTotal = decTax + decSubTotal                 
    
    


    Dim decTax As Decimal
    Dim decTotal As Decimal
    Dim decSubTotal As Decimal

    Instead of making these local to each method, if you make them class members
    as you did with the Const members then they will accumulate the values.

    - Wayne

    Wednesday, March 6, 2019 6:32 PM
  • Hi

    Give this version a try out.

    Option Strict On
    Option Explicit On
    Public Class Form1
      Const _cDecTax As Decimal = 0.07D
      Const _cDecCostOfFacial As Decimal = 8D
      Const _cDecCostOfPedicure As Decimal = 15D
      Const _cDecCostOfManicure As Decimal = 10D
      Const _cDecCostOfHaircut As Decimal = 5D
    
      Dim _cDecTax2 As Decimal = 0
      Dim _cDecTotal As Decimal = 0
      Dim _cDecSubTotal As Decimal = 0
      Private Const V As Decimal = 0
    
      Private Sub btnHaircut_Click(sender As Object, e As EventArgs) Handles btnHaircut.Click
    
        _cDecSubTotal += _cDecCostOfHaircut
        lblSubtotal.Text = _cDecSubTotal.ToString("C2")
    
        _cDecTax2 += _cDecTax * _cDecCostOfHaircut
        lblTax.Text = _cDecTax2.ToString("C2")
    
        _cDecTotal = _cDecTax2 + _cDecSubTotal
        lblTotal.Text = _cDecTotal.ToString("C2")
    
        btnHaircut.Enabled = False
        btnMakeAppointment.Enabled = True
        btnReset.Enabled = True
      End Sub
      Private Sub btnManicure_Click(sender As Object, e As EventArgs) Handles btnManicure.Click
        _cDecSubTotal += _cDecCostOfManicure
        lblSubtotal.Text = _cDecSubTotal.ToString("C2")
    
        _cDecTax2 += _cDecTax * _cDecCostOfManicure
        lblTax.Text = _cDecTax2.ToString("C2")
    
        _cDecTotal = _cDecTax2 + _cDecSubTotal
        lblTotal.Text = _cDecTotal.ToString("C2")
    
        btnManicure.Enabled = False
        btnMakeAppointment.Enabled = True
        btnReset.Enabled = True
      End Sub
      Private Sub btnPedicure_Click(sender As Object, e As EventArgs) Handles btnPedicure.Click
        _cDecSubTotal += _cDecCostOfPedicure
        lblSubtotal.Text = _cDecSubTotal.ToString("C2")
    
        _cDecTax2 += _cDecTax * _cDecCostOfPedicure
        lblTax.Text = _cDecTax2.ToString("C2")
    
        _cDecTotal = _cDecTax2 + _cDecSubTotal
        lblTotal.Text = _cDecTotal.ToString("C2")
    
        btnPedicure.Enabled = False
        btnMakeAppointment.Enabled = True
        btnReset.Enabled = True
      End Sub
      Private Sub btnFacial_Click(sender As Object, e As EventArgs) Handles btnFacial.Click
        _cDecSubTotal += _cDecCostOfFacial
        lblSubtotal.Text = _cDecSubTotal.ToString("C2")
    
        _cDecTax2 += _cDecTax * _cDecCostOfFacial
        lblTax.Text = _cDecTax2.ToString("C2")
    
        _cDecTotal = _cDecTax2 + _cDecSubTotal
        lblTotal.Text = _cDecTotal.ToString("C2")
    
        btnFacial.Enabled = False
        btnMakeAppointment.Enabled = True
        btnReset.Enabled = True
      End Sub
      Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        ' This code resets the selected buttons
        ResetAll()
      End Sub
      Private Sub btnMakeAppointment_Click(sender As Object, e As EventArgs) Handles btnMakeAppointment.Click
        ' This code resets the choices and we assume that the appointent is made.
        ResetAll()
      End Sub
      Sub ResetAll()
        btnHaircut.Enabled = True
        btnManicure.Enabled = True
        btnPedicure.Enabled = True
        btnFacial.Enabled = True
        btnReset.Enabled = False
        btnMakeAppointment.Enabled = False
    
        _cDecTax2 = 0
        _cDecTotal = 0
        _cDecSubTotal = 0
    
        lblTotal.Text = CType(V, String)
        lblSubtotal.Text = CType(V, String)
        lblTax.Text = CType(V, String)
      End Sub
      Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
    
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    Thursday, March 7, 2019 9:13 PM
  • Thank you so much!! 
    Thursday, March 7, 2019 9:49 PM
  • Im a student currently learning Visual Basic. I have coded and made this application for a "salon" offers 4 choices (buttons) Haircut, pedicure, manicure and facial. all with separate prices and it should have a accumulating total so that when haircut is chosen then manicure the subtotal and tax boxes should adjust to the new price. I have the Total correct it adds up correctly when all boxes are chosen where as the subtotal boxes and tax box only show the amount for the individual selection. I can not figure out why the total adds up correctly but the subtotal and tax doesnt. 
    Option Strict On
    Public Class frmSalonSpa
    
        Const _cDecTax As Decimal = 0.07D
        Const _cDecCostOfFacial As Decimal = 8D
        Const _cDecCostOfPedicure As Decimal = 15D
        Const _cDecCostOfManicure As Decimal = 10D
        Const _cDecCostOfHaircut As Decimal = 5D
    
        Dim _cDecTax2 As Decimal = 0
        Dim _cDecTotal As Decimal = 0
        Dim _cDecSubTotal As Decimal = 0
        Private Const V As Decimal = 0
    
    
    
    
        Private Sub btnHaircut_Click(sender As Object, e As EventArgs) Handles btnHaircut.Click
           
            _cDecSubTotal = _cDecCostOfHaircut + _cDecSubTotal
            lblSubtotal.Text = _cDecSubTotal.ToString("C2")          
            lblSubtotal.Text = _cDecCostOfHaircut.ToString("C2")    
    
            _cDecTax2 = _cDecTax * _cDecCostOfHaircut
            lblTax.Text = _cDecTax2.ToString("C2")
            lblTax.Text = _cDecTax2.ToString("C2")
    
            _cDecTotal = _cDecTax2 + _cDecSubTotal                 
            lblTotal.Text = _cDecCostOfHaircut.ToString("C2")        
            lblTotal.Text = _cDecTotal.ToString("C2")
    
    
            btnHaircut.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True
    
    
    
        End Sub
    
        Private Sub btnManicure_Click(sender As Object, e As EventArgs) Handles btnManicure.Click
            
    
            _cDecSubTotal = _cDecCostOfManicure + _cDecSubTotal 
            _cDecTax2 = _cDecTax * _cDecCostOfManicure          
            _cDecTotal = _cDecTax + _cDecSubTotal                 
    
            lblSubtotal.Text = _cDecSubTotal.ToString("C2")            
            lblSubtotal.Text = _cDecCostOfManicure.ToString("C2")     
            lblTotal.Text = _cDecCostOfManicure.ToString("C2")        
    
    
            lblTotal.Text = _cDecTotal.ToString("C2")
            lblTax.Text = _cDecTax2.ToString("C2")
    
    
    
    
    
            btnManicure.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True
    
        End Sub
    
        Private Sub btnPedicure_Click(sender As Object, e As EventArgs) Handles btnPedicure.Click
            
    
            _cDecSubTotal = _cDecCostOfPedicure + _cDecSubTotal  
            _cDecTax2 = _cDecTax * _cDecCostOfPedicure          
            _cDecTotal = _cDecTax2 + _cDecSubTotal                 
    
            lblSubtotal.Text = _cDecSubTotal.ToString("C2")            
            lblSubtotal.Text = _cDecCostOfPedicure.ToString("C2")     
            lblTotal.Text = _cDecCostOfPedicure.ToString("C2")        
    
    
            lblTotal.Text = _cDecTotal.ToString("C2")
            lblTax.Text = _cDecTax2.ToString("C2")
    
    
            btnPedicure.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True
    
    
        End Sub
    
        Private Sub btnFacial_Click(sender As Object, e As EventArgs) Handles btnFacial.Click
          
    
            _cDecSubTotal = _cDecCostOfFacial + _cDecSubTotal  
            _cDecTax2 = _cDecTax * _cDecCostOfFacial          
            _cDecTotal = _cDecTax2 + _cDecSubTotal                 
    
            lblSubtotal.Text = _cDecSubTotal.ToString("C2")            
            lblSubtotal.Text = _cDecCostOfFacial.ToString("C2")     
            lblTotal.Text = _cDecCostOfFacial.ToString("C2")        
    
    
            lblTotal.Text = _cDecTotal.ToString("C2")
            lblTax.Text = _cDecTax2.ToString("C2")
    
    
            btnFacial.Enabled = False
            btnMakeAppointment.Enabled = True
            btnReset.Enabled = True
    
        End Sub
    
        Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
            ' This code resets the selected buttons
    
            btnHaircut.Enabled = True
            btnManicure.Enabled = True
            btnPedicure.Enabled = True
            btnFacial.Enabled = True
            btnReset.Enabled = False
            btnMakeAppointment.Enabled = False
    
            lblTotal.Text = CType(V, String)
            lblSubtotal.Text = CType(V, String)
            lblTax.Text = CType(V, String)
    
        End Sub
    
        Private Sub btnMakeAppointment_Click(sender As Object, e As EventArgs) Handles btnMakeAppointment.Click
            ' This code resets the choices and we assume that the appointent is made.
    
    
    
            btnHaircut.Enabled = True
            btnManicure.Enabled = True
            btnPedicure.Enabled = True
            btnFacial.Enabled = True
            btnReset.Enabled = False
            btnMakeAppointment.Enabled = False
    
            lblTotal.Text = CType(V, String)
            lblSubtotal.Text = CType(V, String)
            lblTax.Text = CType(V, String)
    
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
    
        End Sub



    I see you took my advice in your earlier thread and moved the accumulating
    variables to class scope and removed the local definitions in the methods. 
    It would be proper Netiquette if you acknowledged in that earlier thread
    that the suggestion(s) helped move your coding in the right direction.

    As to the code you posted in this thread, you really just needed to think
    more carefully about the steps you were taking and the results on the
    output. Consider:

    >_cDecSubTotal = _cDecCostOfHaircut + _cDecSubTotal
    >lblSubtotal.Text = _cDecSubTotal.ToString("C2")          
    >lblSubtotal.Text = _cDecCostOfHaircut.ToString("C2")

    Here you set lblSubtotal.Text to _cDecSubTotal and then you immediately 
    change that same text to _cDecCostOfHaircut. Rather obviously wrong.

    >_cDecTax2 = _cDecTax * _cDecCostOfHaircut
    >lblTax.Text = _cDecTax2.ToString("C2")
    >lblTax.Text = _cDecTax2.ToString("C2")

    Why are you doing this assignment twice in a row? What was that supposed to
    accomplish?

    >_cDecTotal = _cDecTax2 + _cDecSubTotal                 
    >lblTotal.Text = _cDecCostOfHaircut.ToString("C2")        
    >lblTotal.Text = _cDecTotal.ToString("C2")

    Why did you assign _cDecCostOfHaircut to lblTotal.Text (which certainly looks
    wrong) and then immediately assign _cDecTotal to that very same lblTotal.Text?
    What point was there to the first assignment?

    It should be rather easy to understand and recognize that if you change a
    variable or property twice in rapid succession with no intervening operations
    then the first assignment will be completely overwritten and therefore serves
    no useful purpose.

    >lblSubtotal.Text = _cDecSubTotal.ToString("C2")            
    >lblSubtotal.Text = _cDecCostOfManicure.ToString("C2")     
    >lblTotal.Text = _cDecCostOfManicure.ToString("C2")

    After correctly setting lblSubtotal.Text to _cDecSubTotal why did you 
    immediately change it to _cDecCostOfManicure?

    Why are you setting lblSubtotal.Text and lblTotal.Text to _cDecCostOfManicure?

    The same illogical assignments are made in the Pedicure and Facial methods.

    I think you would be farther ahead in your studies if you take the time to 
    correct the glaring errors in your own code rather than relying on code 
    provided by others.

    - Wayne

    Friday, March 8, 2019 4:14 AM