Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8617443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:51:34+00:00 2026-06-12T05:51:34+00:00

I have this so far on one of my programs and I would like

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:51:35+00:00Added an answer on June 12, 2026 at 5:51 am

    There are several ways, but looking at what you already have, why not just reread the labels back into the variables you want?

    private void button2_Click(object sender, EventArgs e)
    {
        int thousands = Convert.ToInt32(label6.Text);
        int hundreds = Convert.ToInt32(label7.Text);
        //...etc
    }
    

    You could also just set globals instead of locals, ie declare your ints outside of any method call

    int thousands;
    int hundreds;
    int tens;
    int ones;
    private void button1_Click(object sender, EventArgs e)
    {
        //...code
        thousands = digits / 1000;
        hundreds = (digits - (thousands * 1000)) / 100;
        tens = (digits - ((hundreds * 100) + (thousands * 1000))) / 10;
        ones = (digits - ((tens * 10) + (hundreds * 100) + (thousands * 1000))) / 1;
    }
    private void button2_Click(object sender, EventArgs e)
    {
        Console.WriteLine(thousands); //...etc
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks to everyone out there helping newbies like me. So far I have this:
I would like a batch file to launch two separate programs then have the
I have this so far but the Column 'name' is ambiguous, so I want
I have this so far but I don't know how to write over the
I have this so far: http://jsfiddle.net/u5vhS/54/ . What I want to be able to
I'm using the javascript module pattern, and have this so far: var APP; if(APP
I have this code so far which perfectly but relies on there being a
So far i have this: mov ah,02h mov cl,11001100001111011101000b ;6,692,584 in dec mov dl,0
I have been using this so far system 'strings binary-file.dmp | grep search_string' Is
I have this trigger which works functionally (as far as I can tell by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.