C ++ Windows Forms应用程序未处理的异常错误,当文本框为空时 [英] C++ Windows Forms application unhandled exception error when textbox empty

查看:123
本文介绍了C ++ Windows Forms应用程序未处理的异常错误,当文本框为空时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio中为C ++课程建立温度转换应用程序。这是一个Windows窗体应用程序。

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

我的问题是,当我运行应用程序,如果我没有输入任何txtFahrenheit或txtCelsius2文本框中,我得到以下错误:

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:

mscorlib.dll中出现类型为'System.FormatException'的未处理异常

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

我被告知尝试使用:

Double::TryParse()

推荐答案

这是一个全新的C ++程序,并且无法弄明白如何使用它。将检查您的文本框中的条目是否可转换为数字。

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
}    

这篇关于C ++ Windows Forms应用程序未处理的异常错误,当文本框为空时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆