title: C++ Windows Forms application unhandled exception error when textbox empty
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/12662951/c-windows-forms-application-unhandled-exception-error-when-textbox-empty">C++ Windows Forms application unhandled exception error when textbox empty</a>  </p>
  </blockquote>
  
  
  
  <p>I'm building a temperature conversion application in Visual Studio for a C++ course. It's a Windows Forms application and the code that I've written is below. There's other code to of course, but I'm not sure you need it to help me.</p>
  
  <p>My problem is, when I run the application if I don't have anything entered into either the txtFahrenheit or txtCelsius2 textboxes I get the following error: </p>
  
  <p>"An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll"</p>
  
  <p>The application only works right now when a number is entered into both of the textboxes.</p>
  
  <pre><code>private: System::Void btnFtoC_Click(System::Object^  sender, System::EventArgs^  e) 
               {               
                  // Convert the input in the Fahrenheit textbox to a double datatype named fahrenheit for manipulation
                  double fahrenheit = Convert::ToDouble(txtFahrenheit-&gt;Text);
                  // Set the result string to F * (5/9) -32
                  double result = fahrenheit * .5556 - 32;
                  // Set the Celsius text box to display the result string
                  txtCelsius-&gt;Text = result.ToString();
               }
  
  private: System::Void btnCtoF_Click(System::Object^  sender, System::EventArgs^  e) 
               {
                  // Convert the input in the Celsius textbox to a double datatype name celsius for manipulation
                  double celsius = Convert::ToDouble(txtCelsius2-&gt;Text);
                  // Set the result2 string to C * (9/5) + 32
                  double result2 = celsius * 1.8 + 32;
                  // Set the Fahrenheit text box to display the result2 string
                  txtFahrenheit2-&gt;Text = result2.ToString();
               }
  </code></pre>