繁体   English   中英

格式异常未处理(double.parse)

[英]formatexception was unhandled (double.parse)

我的应用程序出现问题。 当我单击确定或在消息框中取消时。 它发生了。 这是我的代码。 它说线不写。 它说输入字符串不在格式中。 我该怎么办。 这是截图

private void button1_Click(object sender, EventArgs e)
    {
       if ((textBox1.Text == "") || (textBox2.Text == "") || (textBox3.Text == "") || (textBox4.Text == ""))
        {
            MessageBox.Show("Please Fill All The Informations", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
        };



        double foot, inches;
        double height;
        double weight;
        double age;
        double BMRM;
        double BMRF;
        double BMI;

        foot = double.Parse(textBox2.Text); 
        inches = double.Parse(textBox1.Text);
        height = 30.48 * (foot + (0.083 * inches));
        weight = double.Parse(textBox3.Text);
        age = double.Parse(textBox4.Text);
        BMRM = 66 + (13.7 * weight) + (5 * height) - (6.8 * age);
        BMRF = 655 + (9.6 * weight) + (1.8 * height) - (4.7 * age);
        BMI = (weight / ((height * height) / 10000));

        if (radioButton1.Checked)
        {
            textBox5.Text = BMRM.ToString();
        };
        if (radioButton2.Checked)
        {
            textBox5.Text = BMRF.ToString();
        };
        textBox6.Text = BMI.ToString();

        if (BMI <= 18.5)
        {
            textBox7.Text = "Your weight is low. You have to eat properly.";
        };
        if (BMI > 18.5 && BMI <= 24.9)
        {
            textBox7.Text = "You are Healthy";
        };
        if (BMI > 25 && BMI <= 29.9)
        {
            textBox7.Text = "You have gained a little fat";
        };

        if (BMI > 30 && BMI <= 34.9)
        {
            textBox7.Text = "You are in the fist step of Fat.You have take exercise regularly";
        };
        if (BMI > 35 && BMI < 40)
        {
            textBox7.Text = "You are in the second step of Fat. You need to exercise regularly";
        }
        if (BMI > 40)
        {
            textBox7.Text = "You have gained a lot of fat. It can cause you death. Please take Doctor's advise";
        };

您可以这样尝试:

double foot;
if(!double.TryParse(textBox2.Text,out foot))
  MessageBox.Show(String.Format("Invalid input, foot must be a number"));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM