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

  • Home
  • SEARCH
  • 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 5929717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:27:31+00:00 2026-05-22T14:27:31+00:00

This is the code I have so far: public partial class Form2 : Form

  • 0

This is the code I have so far:

public partial class Form2 : Form
{
    public Double X;

    public Form2()
    {
        InitializeComponent();
    }


    private void button2_Click(object sender, EventArgs e)
    {
        if(textBox1.Text != "")
        X = Convert.ToDouble(textBox1.Text);
        X *= 0.001;
        label3.Text = "metros";
    }


    private void button3_Click(object sender, EventArgs e)
    {
        if (textBox1.Text != "")
        X = Convert.ToDouble(textBox1.Text);
        X *= 0.62;
        label3.Text = "milhas";
    }

    private void button4_Click(object sender, EventArgs e)
    {
        if (textBox1.Text != "")
        X = Convert.ToDouble(textBox1.Text);
        label3.Text = "quilómetros";
    }

    private void button5_Click(object sender, EventArgs e)
    {
        if (textBox1.Text != "")
        X = Convert.ToDouble(textBox1.Text);
        X *= 3280,84;
        label3.Text = "pés";
    }

    private void button6_Click(object sender, EventArgs e)
    {
        if (textBox1.Text != "")
        X = Convert.ToDouble(textBox1.Text);
        X *= 0.17998560115190784737;
        label3.Text = "léguas";
    }

    private void button1_Click(object sender, EventArgs e)
    {

        textBox2.Text = Convert.ToString(X);

    }

This is how the window looks like:
Active Form

What these do is, when you insert a value on textBox1 (the red one on the middle left of the window), you then select the measurement from the buttons on the right, this will convert the introduced value to kilometres and store it in the variable X and write the chosen measurment on a label to the right of the textBox1.

When you press the “Converter” button, (for now) I wanted the textBox2 to show X, however, this only works when I press “metros” or “pés”, if I choose one of the other buttons for the conversion it will simply do nothing…

Does someone have any idea of what’s wrong?

And also, side question, how do you select items from the comboBox?

  • 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-05-22T14:27:31+00:00Added an answer on May 22, 2026 at 2:27 pm

    Firstly, if statements only execute the very next statement if their condition is met:

    if(textBox1.Text != "")
    X = Convert.ToDouble(textBox1.Text);  // only run if 'if' is true
    X *= 0.001;                           // always run
    label3.Text = "metros";               // always run
    

    The if is associated with the next line. If you want all of the following code to be associated with the if, then you need to open a block:

    if(textBox1.Text != "")
    {
       X = Convert.ToDouble(textBox1.Text);
       X *= 0.001;
       label3.Text = "metros";
    }
    

    To help guard against this, I would advise adopting a consistent style for single-line if statements:

    if (something) SomeStatement(); // same line
    
    if (something)
        SomeStatement(); // indented
    
    if (something)
    {
        SomeStatement(); // single statement block
    }
    

    It’s possible some of your buttons are not working because the link between the event handler methods and the events has been broken. You should open the designer and ensure that each of the buttons has a Click handler assigned.

    With respect to the combo-box part of your question: ComboBox.SelectedItem allows you to get or set the selected item. Alternatively you can use ComboBox.SelectedIndex to get or set the index of the item that is selected.

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

Sidebar

Related Questions

I have this code so far which perfectly but relies on there being a
This is what I have as far as code, it is in the first
So I have this code for these Constructors of the Weapon class: Weapon(const WeaponsDB
Suppose I have this code: var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"]
Say I have this code - public interface ParentInterface1 { public List<? extends ChildInterface1>
Here's my code so far. I have the main form and wcf objects that
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
So I have this code that takes care of command acknowledgment from remote computers,
So I have this code in a google app engine template: <select name='voter'> {%
Hey I have this code right here: http://pastie.org/534470 And on line 109 I get

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.