C++ Windows Forms application unhandled exception error when textbox empty

ぐ巨炮叔叔 提交于 2019-12-02 16:24:53

问题


I'm building a temperature conversion application in Visual Studio for a C++ course. It's a Windows Forms application.

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:

"An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll"

The application only works right now when a number is entered into both of the textboxes.

I was told to try and use this:

Double::TryParse()

but I'm brand new to C++ and can't figure out how to use it, even after checking the MSDN library.


回答1:


This will check that the entry in your textbox is convertible to a number.

double val;
bool result = System::Double::TryParse(txtFahrenheit->Text,val);

if (result)
{
    //Converted successfully, you can use val
}
else
{
    //Error
}    


来源:https://stackoverflow.com/questions/12662951/c-windows-forms-application-unhandled-exception-error-when-textbox-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!