重複の可能性:
テキストボックスが空の場合の C++ Windows フォームアプリケーションのハンドルされていない例外エラー
C++ コース用に Visual Studio で温度変換アプリケーションを作成しています。これは Windows フォーム アプリケーションであり、私が作成したコードは以下のとおりです。もちろん、他のコードもありますが、私を助けるためにそれが必要かどうかはわかりません。
私の問題は、txtFahrenheit または txtCelsius2 テキストボックスに何も入力していない場合にアプリケーションを実行すると、次のエラーが表示されることです。
「タイプ 'System.FormatException' の未処理の例外が mscorlib.dll で発生しました」
アプリケーションは、両方のテキスト ボックスに数値が入力された場合にのみ機能します。
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->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->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->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->Text = result2.ToString();
}