formatexception was unhandled (double.parse)

本文关键字:parse double was unhandled formatexception | 更新日期: 2023-09-27 18:34:18

我的应用程序遇到了一些问题。 当我在消息框中单击"确定"或"取消"时。 它发生了。这是我的代码。它说的弦不是写的。它说输入字符串不在甲酸盐中。我该怎么办。这是截图

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";
        };

formatexception was unhandled (double.parse)

你可以

这样尝试:

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