Sum of Multiple Text Boxes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Derek

    Sum of Multiple Text Boxes

    I am trying to add the text of several textboxes as a sum
    using the + sign but even converting to integer it is
    concatenating. Any help would be greatly appreciated.





    Dim price1 As Integer

    Dim price2 As Integer

    Dim price3 As Integer

    Dim price4 As Integer

    Dim price5 As Integer

    Dim TotalPrice As Integer



    price1 = CType(txtcost1. Text, Integer)

    price2 = CType(txtcost2. Text, Integer)

    price3 = CType(txtcost3. Text, Integer)

    price4 = CType(txtcost4. Text, Integer)

    price5 = CType(txtcost5. Text, Integer)

    TotalPrice = price1 + price2 + price3 + price4 +
    price5

    txtEC.Text = TotalPrice

    ShowFields()


  • William Ryan

    #2
    Re: Sum of Multiple Text Boxes

    Derek:

    I just copied your code onto a form and added the five textboxes. I
    commented out ShowFields because I don't know what that does. It works
    fine. Being that everything here is an int, I'm inclined to think something
    else is the problem. you could also try price1.Parse(tx tcost1.text) etc but
    Ints are going to add not concatenate.

    If you debug.WriteLine after the TotalPrice line,
    Debug.WriteLine (TotalPrice.ToS tring), what number do you get?

    Also, if any of those text boxes contain nonnumeric data or are empty,
    you're going to have some drama, so make sure you don't let the user hit the
    Calc button until all the info is good.

    Post the rest of the code block, we can figure this one out.

    HTH,

    Bill

    HTH,

    Bill
    "Derek" <derek.mendez@c harleston.af.mi l> wrote in message
    news:63bb01c37d 43$a218a1f0$a60 1280a@phx.gbl.. .[color=blue]
    > I am trying to add the text of several textboxes as a sum
    > using the + sign but even converting to integer it is
    > concatenating. Any help would be greatly appreciated.
    >
    >
    >
    >
    >
    > Dim price1 As Integer
    >
    > Dim price2 As Integer
    >
    > Dim price3 As Integer
    >
    > Dim price4 As Integer
    >
    > Dim price5 As Integer
    >
    > Dim TotalPrice As Integer
    >
    >
    >
    > price1 = CType(txtcost1. Text, Integer)
    >
    > price2 = CType(txtcost2. Text, Integer)
    >
    > price3 = CType(txtcost3. Text, Integer)
    >
    > price4 = CType(txtcost4. Text, Integer)
    >
    > price5 = CType(txtcost5. Text, Integer)
    >
    > TotalPrice = price1 + price2 + price3 + price4 +
    > price5
    >
    > txtEC.Text = TotalPrice
    >
    > ShowFields()
    >
    >[/color]


    Comment

    • Derek Mendez

      #3
      Re: Sum of Multiple Text Boxes


      What you said about empty strings etc. was right. I was adding the 5th
      textbox in code but not showing it to input data.


      Thanks so much!

      Derek

      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Derek

        #4
        Re: Sum of Multiple Text Boxes

        What you said about empty strings etc. was right. I was
        adding the 5th
        textbox in code but not showing it to input data.


        Thanks so much!

        Derek

        [color=blue]
        >-----Original Message-----
        >Derek:
        >
        >I just copied your code onto a form and added the five[/color]
        textboxes. I[color=blue]
        >commented out ShowFields because I don't know what that[/color]
        does. It works[color=blue]
        >fine. Being that everything here is an int, I'm inclined[/color]
        to think something[color=blue]
        >else is the problem. you could also try price1.Parse[/color]
        (txtcost1.text) etc but[color=blue]
        >Ints are going to add not concatenate.
        >
        >If you debug.WriteLine after the TotalPrice line,
        >Debug.WriteLin e(TotalPrice.To String), what number do you[/color]
        get?[color=blue]
        >
        >Also, if any of those text boxes contain nonnumeric data[/color]
        or are empty,[color=blue]
        >you're going to have some drama, so make sure you don't[/color]
        let the user hit the[color=blue]
        >Calc button until all the info is good.
        >
        >Post the rest of the code block, we can figure this one[/color]
        out.[color=blue]
        >
        >HTH,
        >
        >Bill
        >
        >HTH,
        >
        >Bill
        >"Derek" <derek.mendez@c harleston.af.mi l> wrote in message
        >news:63bb01c37 d43$a218a1f0$a6 01280a@phx.gbl. ..[color=green]
        >> I am trying to add the text of several textboxes as a[/color][/color]
        sum[color=blue][color=green]
        >> using the + sign but even converting to integer it is
        >> concatenating. Any help would be greatly appreciated.
        >>
        >>
        >>
        >>
        >>
        >> Dim price1 As Integer
        >>
        >> Dim price2 As Integer
        >>
        >> Dim price3 As Integer
        >>
        >> Dim price4 As Integer
        >>
        >> Dim price5 As Integer
        >>
        >> Dim TotalPrice As Integer
        >>
        >>
        >>
        >> price1 = CType(txtcost1. Text, Integer)
        >>
        >> price2 = CType(txtcost2. Text, Integer)
        >>
        >> price3 = CType(txtcost3. Text, Integer)
        >>
        >> price4 = CType(txtcost4. Text, Integer)
        >>
        >> price5 = CType(txtcost5. Text, Integer)
        >>
        >> TotalPrice = price1 + price2 + price3 + price4 +
        >> price5
        >>
        >> txtEC.Text = TotalPrice
        >>
        >> ShowFields()
        >>
        >>[/color]
        >
        >
        >.
        >[/color]

        Comment

        Working...