本文介绍了我需要在3个文本框中输入正数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个文本框,2个文本框值可能大于零,一个文本框值为0。但我需要3个文本框值结果是积极的。 for.eg:5*5*0=25



 尝试 
{
if (txtNumber.Text == string .Empty)
{
number =(txtNumber.Text == string .Empty || txtNumber.Text == 0)? 0
Convert.ToInt32(txtNumber.Text);

}
else
{
number = Convert.ToInt32(txtNumber.Text);
}

if (txtLength.Text == string 。空)
{
lenght =(txtLength.Text == string .Empty || txtLength.Text == 0)? 0
Convert.ToDouble(txtLength.Text);

}
else
{
lenght = Convert.ToDouble(txtLength.Text);
}
if (txtHeight.Text == string .Empty)
{
height =(txtHeight.Text == string .Empty || txtHeight.Text == 0)? 0
Convert.ToDouble(txtHeight.Text);

}
else
{
height = Convert.ToDouble(txtHeight.Text);
}
if (txtBreadth.Text == string .Empty)
{
breadth =(txtBreadth.Text == string .Empty || txtBreadth.Text == 0)? 0
Convert.ToDouble(txtBreadth.Text);
}
else
{
breadth = Convert.ToDouble(txtBreadth.Text);
}

txtQuantity.Text =(number * lenght * breadth * height).ToString();

}
catch (例外)
{
MessageBox.Show( 发生错误,请再试一次!!!);
}





我的尝试:



我需要在3个文本框中输入正数

解决方案




I have 3 textboxes and 2 textboxes value is maybe greater than zero and one text boxes values is 0 . But I need to the 3 textbox values result is positive. for.eg:5*5*0=25

try
           {
               if (txtNumber.Text == string.Empty)
               {
                   number = (txtNumber.Text == string.Empty || txtNumber.Text == "0") ? 0 :
                   Convert.ToInt32(txtNumber.Text);

               }
               else
               {
                   number = Convert.ToInt32(txtNumber.Text);
               }

               if (txtLength.Text == string.Empty)
               {
                   lenght = (txtLength.Text == string.Empty || txtLength.Text == "0") ? 0 :
                   Convert.ToDouble(txtLength.Text);

               }
               else
               {
                   lenght = Convert.ToDouble(txtLength.Text);
               }
               if (txtHeight.Text == string.Empty)
               {
                   height = (txtHeight.Text == string.Empty || txtHeight.Text == "0") ? 0 :
                   Convert.ToDouble(txtHeight.Text);

               }
               else
               {
                   height = Convert.ToDouble(txtHeight.Text);
               }
               if (txtBreadth.Text == string.Empty)
               {
                   breadth = (txtBreadth.Text == string.Empty || txtBreadth.Text == "0") ? 0 :
                   Convert.ToDouble(txtBreadth.Text);
               }
               else
               {
                   breadth = Convert.ToDouble(txtBreadth.Text);
               }

               txtQuantity.Text = (number * lenght * breadth * height).ToString();

           }
           catch (Exception)
           {
               MessageBox.Show("Error occured, Please try again!!!");
           }



What I have tried:

I need to positive number result in 3 text boxes

解决方案




这篇关于我需要在3个文本框中输入正数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 13:02