...

View Full Version : C# beginner having trouble



crank01
01-07-2012, 10:28 PM
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:
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 :confused:

Please help :(

crank01
01-08-2012, 04:25 AM
I'm still looking for help, if anyones got any ideas I would be really grateful.

Is this even possible to do?

crank01
01-08-2012, 08:58 PM
friendly bumping for help from you guys :thumbsup:

alykins
01-09-2012, 02:45 PM
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.";
}
}
}
}

crank01
01-09-2012, 11:18 PM
Thanks alykins :) it works, and I thanked you yet again lol

alykins
01-10-2012, 01:26 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum