954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to update label when new input is put in text and button clicked?

Hello,
The form i am doing takes from the user the item price, then it will calcuate the subtotal, tax, shipping, and total when the button is clicked. How can i update it so if the user adds another item it will update the subtotal, tax, and total when the button is clicked.

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
        
        Dim dblItem As Double
        Dim dblSub As Double
        Dim dblTax As Double
        Dim intShipping As Integer
        Dim dblTotal As Double
        Dim dblnewSub As Double
        Dim dblnewTax As Double
        Dim dblnewtotal As Double

        Double.TryParse(txtItem.Text, dblItem)

        dblSub = dblItem + dblSub

            lblSub.Text = Convert.ToString(dblSub)

            dblTax = dblSub * 0.03
            lblTax.Text = Convert.ToString(dblTax)

            intShipping = "15.00"
            lblShipping.Text = Convert.ToString(intShipping)

            dblTotal = dblSub + dblTax + intShipping
            lblTotal.Text = Convert.ToString(dblTotal)

            If dblTotal >= 100 Then
                intShipping = "0.00"
                lblShipping.Text = Convert.ToString(intShipping)
        ElseIf dblTotal < 100 Then
            intShipping = "15.00"
            lblShipping.Text = Convert.ToString(intShipping)
            End If
kass2112
Newbie Poster
5 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
 

Calculate the new values for subtotal, tax, and total and put them in whatever control displays the values
txtSubtotal.text = subtotal

or lblTax.caption = tax

WaltP
Posting Sage w/ dash of thyme
Moderator
10,507 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

That just multiplies the first input by two. How can it add new items inputed from the user in the textbox to the labels? So lets say i put in 35, it will show subtotal of 35, tax of 1.05, shipping 15, and total of 51.05. Now if i put in another number like 40 I would want it to add it to the subtotal, tax, and total of the first.

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
        
        Dim dblItem As Double
        Dim dblSub As Double
        Dim dblTax As Double
        Dim intShipping As Integer
        Dim dblTotal As Double
        Dim dblnewSub As Double
        Dim dblnewTax As Double
        Dim dblnewtotal As Double

        Double.TryParse(txtItem.Text, dblItem)

        dblSub = dblItem + dblSub



            dblTax = dblSub * 0.03
            lblTax.Text = Convert.ToString(dblTax)

            intShipping = "15.00"
            lblShipping.Text = Convert.ToString(intShipping)

            dblTotal = dblSub + dblTax + intShipping
            lblTotal.Text = Convert.ToString(dblTotal)

            If dblTotal >= 100 Then
                intShipping = "0.00"
                lblShipping.Text = Convert.ToString(intShipping)
        ElseIf dblTotal < 100 Then
            intShipping = "15.00"
            lblShipping.Text = Convert.ToString(intShipping)
            End If

        dblnewSub = dblItem + dblSub
        lblSub.Text = Convert.ToString(dblnewSub)

        dblnewTax = dblnewSub * 0.03
        lblTax.Text = Convert.ToString(dblnewTax)

        dblnewtotal = dblnewSub + dblnewTax + dblTotal
        lblTotal.Text = Convert.ToString(dblnewtotal)


    End Sub
kass2112
Newbie Poster
5 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
 
kass2112
Newbie Poster
5 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
 

We don't bump here.

The reason I haven't answered is your comments were nonsense based on my previous post:
That just multiplies the first input by two.


And your following question makes no sense for anyone with 2nd grade math:How can it add new items inputed from the user in the textbox to the labels? So lets say i put in 35, it will show subtotal of 35, tax of 1.05, shipping 15, and total of 51.05. Now if i put in another number like 40 I would want it to add it to the subtotal, tax, and total of the first.
Use the + sign somewhere in your code to add the new values to the old values.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,507 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

Hi sorry about the 'bump' and the misinformation of the last question. What i am trying to say is how can i have the button's click event keep on adding to the total when the user types in the textbox?

kass2112
Newbie Poster
5 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
 

And I don't understand what your problem is.

You have all the values accessible.
You know how to convert a control's text field into a value.
You know how to add two values.
You know how to load a value into a control's text field.

Clearly you are having a specific problem that your general description does not address.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,507 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

Solved it.
Thanks for the help WaltP.

kass2112
Newbie Poster
5 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: