Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts

    Arrow C# beginner having trouble

    A friend gave me the idea of making a golf scorecard which tracks for each hole what you got, and then adds that number to the total. This is what I'm trying to do but I am having trouble on adding the numbers to the total textBox. So far I have 19 textBoxes. 1-18 for each hole, the 19th textBox for Total. Now I have been trying desperately to take textBox1 and adding that to textBoxTotal, now I have done this with: textBoxtotal.Text = textBox1.Text, but now whenever I try doing it for the other textBoxes(Golf Holes) all it does is add that number AFTER the previous textBox; and does not sum up all of the textBoxes. If possible I would like it to keep a running count in the total textBox, meaning as I type numbers into each textBox it already totals them.

    This is a Windows Form Application, incase you were wondering.

    for the total textBox I have:
    Code:
    private void textBoxTotal_TextChanged(object sender, EventArgs e)
            {
                int box1;
                int box2;
                int boxTotal;
                box1 = Convert.ToInt32(textBox1.Text);
                box2 = Convert.ToInt32(textBox2.Text);
                boxTotal = box1 + box2;
                textBoxTotal.Text = boxTotal.ToString();
                
                
            }
    but nothing won't show up in the Total text box

    Please help
    Last edited by crank01; 01-07-2012 at 11:00 PM.

  • #2
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts
    I'm still looking for help, if anyones got any ideas I would be really grateful.

    Is this even possible to do?
    Last edited by crank01; 01-08-2012 at 08:34 PM.

  • #3
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts
    friendly bumping for help from you guys

  • #4
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,929
    Thanks
    46
    Thanked 203 Times in 202 Posts
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
    
            private int MyTotal = 0;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                Calc(this.textBox1.Text);
            }
    
            private void textBox2_TextChanged(object sender, EventArgs e)
            {
                Calc(this.textBox2.Text);
            }
    
            private void Calc(string NumText)
            {
                int MyInt = 0;
    
                try
                {
                    MyInt = Convert.ToInt32(NumText);
                    lbl1.Text = "";
                    MyTotal += MyInt;
                    textBox3.Text = MyTotal.ToString();
                }
    
                catch
                {
                    lbl1.Text = "You did not enter a number.";
                }
            }
        }
    }

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • Users who have thanked alykins for this post:

    crank01 (01-09-2012)

  • #5
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Thanks alykins it works, and I thanked you yet again lol

  • #6
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,929
    Thanks
    46
    Thanked 203 Times in 202 Posts
    Quote Originally Posted by crank01 View Post
    Thanks alykins it works, and I thanked you yet again lol
    no prob I am pretty swamped @ work and home lately so if u have any more Q's in threads PM me like you did (post here first though) but if something is not getting answered and you pm me I will try to find time to check it for you

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

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