View Single Post
 
Old October 29th, 2012, 08:26 PM
MinusZero MinusZero is offline
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Location: Australia
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default Checking if a text box is empty

Hi,

I want to be able to check if a text box is empty, show a message if it is, otherwise it should continue to the else code.

When i run the program and try to convert when nothing is in the text box, it skips the message and goes straight to an error "Input string was not in a correct format."

I have noted where the program stops. I figure its because the empty text box isnt a double. It seems to disregard the empty textbox message. I hope i am not in over my head here.

Code:
private void btnLengthConvert_Click(object sender, EventArgs e)
        {
          //check if textbox is empty  
          if (tbxLengthToConvert == null)
            {
                MessageBox.Show("test");
            }
            else

            //CENTIMETRES
            //check if the centimetre radio button is checked and then run the math
            if (rbCM.Checked == true)
            {
                double length = double.Parse(tbxLengthToConvert.Text); ERROR
                double mm = length * 10;
                double cm = length * 1;
                double mt = length * 0.01;
                double km = length * 0.00001;
                double inches = length * 2.54;
                double feet = length * 0.032808399;

                tbxLenMm.Text = mm.ToString();
                tbxLenCm.Text = cm.ToString();
                tbxLenMetres.Text = mt.ToString();
                tbxLenKm.Text = km.ToString();
                tbxLenIn.Text = inches.ToString();
                tbxLenFt.Text = feet.ToString();

            }
__________________
"These pretzels are making me thirsty"