CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Add the content of multiple textboxes

    You need to convert each textbox to numeric before you add them together rather than after.
    Always use [code][/code] tags when posting code.

  2. #2
    Join Date
    May 2010
    Posts
    3

    Re: Add the content of multiple textboxes

    I figured it out I needed to use Int32.Parse - now it counts.
    Int32 Sum = 0;
    Sum = Int32.Parse(textBox6.Text) + Int32.Parse(textBox7.Text);
    textBox12.Text = Sum.ToString();

  3. #3
    Join Date
    May 2010
    Posts
    3

    [RESOLVED] Add the content of multiple textboxes

    I am writing a yahtzee game. I am trying to add the contents of mutliple textboxes. If textbox6 and textbox7 have 2,2 it should be 4, however it is just catnating 22. Any help would be appreciated. I am in my third week of a c# class.

    private void button3_Click_1(object sender, EventArgs e)
    {
    int Sum = 0;
    Sum = Convert.ToUInt16(textBox6.Text + textBox7.Text);
    textBox12.Text = Sum.ToString();

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Add the content of multiple textboxes

    You need to convert each textbox to numeric before you add them together rather than after.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    May 2010
    Posts
    3

    Re: Add the content of multiple textboxes

    I thought I was converting before adding by using Convert.ToUInt16 before adding
    int Sum = 0;
    Sum = Convert.ToUInt16(textBox6.Text + textBox7.Text);
    //textBox12.Text = Sum.ToString();
    textBox12.Text = Convert.ToString(Sum);

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured