I have this so far on one of my programs and I would like it to be where if you press on one button to break up the number you enter, you enable another button to get that data and save it to an outfile.
private void button1_Click(object sender, EventArgs e)
{
string number = textBox1.Text;
int digits = int.Parse(number);
if (digits > 9999 || digits < 0)
{
MessageBox.Show("That is not a valid number");
}
else
{
int thousands = digits / 1000;
int hundreds = (digits - (thousands * 1000)) / 100;
int tens = (digits - ((hundreds * 100) + (thousands * 1000))) / 10;
int ones = (digits - ((tens * 10) + (hundreds * 100) + (thousands * 1000))) / 1;
label6.Text = thousands.ToString();
label7.Text = hundreds.ToString();
label8.Text = tens.ToString();
label9.Text = ones.ToString();
button2.Enabled = true;
}
I have this so far and it works but for button2, I want these variables that are generated from clicking button one to pass to button2 so when you click on it, it will use those variables to write to a file. Any ideas?
There are several ways, but looking at what you already have, why not just reread the labels back into the variables you want?
You could also just set globals instead of locals, ie declare your ints outside of any method call
Don’t do this too often as if you have tons of globals things can get confusing quick, but for a simple program (which this seems to be) it should be ok.