Question Tax Calculator

Shadow32o

New member
Joined
Sep 6, 2008
Messages
3
Programming Experience
Beginner
Ok, I'm creating this calculator for someone I know... But I ran into a problem...This thing doesn't do decimal's. What it basicly is, is trying to take the data from 4 text boxes and add them up into a label, then take that anwser and multiply it by 0.06. It works fine...unless you use a decimal, then it will just add up the 1st number in each text box... So please help if you can...I'm sort of a begginner...but get the concept...just have this little problem...

Thanks in advance for any help given:D

VB.NET:
Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
        Dim add, add2, add3, add4 As Integer

        add = Val(txtPrice1.Text)
        add2 = Val(txtPrice2.Text)
        add3 = Val(txtPrice3.Text)
        add4 = Val(txtPrice4.Text)

        lblTest.Text = Format(add + add2 + add3 + add4, "currency")
        lblTest2.Text = Format(lblTest.Text * 0.06 + lblTest.Text, "currency")
    End Sub
 
Ok, I'm creating this calculator for someone I know... But I ran into a problem...This thing doesn't do decimal's. What it basicly is, is trying to take the data from 4 text boxes and add them up into a label, then take that anwser and multiply it by 0.06. It works fine...unless you use a decimal, then it will just add up the 1st number in each text box... So please help if you can...I'm sort of a begginner...but get the concept...just have this little problem...

Thanks in advance for any help given:D

VB.NET:
Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
        Dim add, add2, add3, add4 As Integer

        add = Val(txtPrice1.Text)
        add2 = Val(txtPrice2.Text)
        add3 = Val(txtPrice3.Text)
        add4 = Val(txtPrice4.Text)

        lblTest.Text = Format(add + add2 + add3 + add4, "currency")
        lblTest2.Text = Format(lblTest.Text * 0.06 + lblTest.Text, "currency")
    End Sub
When dealing with numbers that may have a decimal you'll need to use one of these three data types: Decimal, Double, Single. When dealing with money values, I recommend using a Decimal. With the code you have, you're using Integers, Integers store whole numbers only.
VB.NET:
Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
        Dim SubTotal, Tax, GrandTotal As Decimal

        SubTotal = CDec(txtPrice1.Text) + CDec(txtPrice2.Text) + CDec(txtPrice3.Text) + CDec(txtPrice4.Text)
        Tax = SubTotal * 0.06D
        GrandTotal = SubTotal + Tax

        SubTOtalLabel.Text = SubTotal.ToString("c"c)
        TaxLabel.Text = Tax.ToString("c"c)
        GrandTotalLabel.Text = GrandTotal.ToString("c"c)
    End Sub
 
Back
Top