-HELP- sum of 2 textboxs and then getting the total in the last textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wlee1970
    New Member
    • Oct 2014
    • 10

    -HELP- sum of 2 textboxs and then getting the total in the last textbox

    I am trying to get 2 numbers from 2 textboxs and get a return sum in the third textbox. the strange thing is that i got it to work with this code that i am going to provide on the last app i worked on, now on the new app i am on it doesnt work at all.. I am not getting any Errors, just shows a zero when i calculate to the sum of the total textbox.

    Code:
    int sum1 = 0;
                int sum2 = 0;
                int result = 0;
    
                if (int.TryParse(txtPrice.Text, out sum1) & int.TryParse(txtQuantity.Text, out sum2))
                    result = sum1 * sum2;
                txtSubTotal.Text = result.ToString();
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    In what way does it not work? Are you getting an error message? What is the error message?

    Also, in your code, you are multiplying, not adding.
    Last edited by Rabbit; Oct 3 '14, 10:50 PM.

    Comment

    • wlee1970
      New Member
      • Oct 2014
      • 10

      #3
      Not getting an error messsage at all.. it just shows a zero in the third sum total textbox

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        I would check the values of all the variables along each step of the code to make sure it's populating correctly.

        Comment

        • wlee1970
          New Member
          • Oct 2014
          • 10

          #5
          I dont see any difference, everything seems to be right but it isnt doing what it suppose to do, examples would be nice :)

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            So you're saying the debugger shows the correct value is the variable result?

            Comment

            • wlee1970
              New Member
              • Oct 2014
              • 10

              #7
              thats correct, no errors, but i get a zero on the total.

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                There's some sort of miscommunicatio n happening. With the code you posted and the description of what you want, it's very unlikely that the value in the variable result is correct.

                You said you wanted to add 2 numbers. But your code shows that you are multiplying. So unless your test numbers are 2 and 2, or something like that, there's no way your result variable should hold the correct value.

                Comment

                • wlee1970
                  New Member
                  • Oct 2014
                  • 10

                  #9
                  What miscommunicatio n are you talking about.. adding two numbers was misdirected, i wanted multiply those numbers to get the sum of the total. Is there another ways to do this, then this type of code...

                  Comment

                  • wlee1970
                    New Member
                    • Oct 2014
                    • 10

                    #10
                    ok I wrote another program using the same code and it worked, would it be something in the program on the inventory system i am working on causing issues or to much code under one button.

                    Comment

                    • wlee1970
                      New Member
                      • Oct 2014
                      • 10

                      #11
                      ok what i had to do is add another button to the inventory system and it seem to work out... i had to much code under the Add button, when I created the Sum button everything stop freaking out.

                      Comment

                      • Rabbit
                        Recognized Expert MVP
                        • Jan 2007
                        • 12517

                        #12
                        I'm not sure I understand what you just said but it sounds like you fixed your problem?

                        Comment

                        Working...