I have been working on this for a while, and I am missing the obvious. I am trying to make sure that if the value of the text field is left empty, no error will be selected and instead a simple message will be shown in the text field. However, what I have, and a few other methods that I tried, it seems, did not work. I cannot understand why this does not work and what I need to do differently.
The basics:
This is a simple calculator that allows you to enter measurements of your waist, neck and height for use in a formula that calculates their estimated percentage of body fat. The calculation works correctly if the field remains empty.
Thanks for any help!
My code is:
if (TBWaist.Text == null || TBNeck.Text == null || TBHeight.Text == null)
{
TBBodyFat.Text = "Value missing";
}
else
if (TBWaist.Text != null & TBNeck.Text != null & TBHeight.Text != null)
{
double waist;
double neck;
double height;
waist = Convert.ToDouble(TBWaist.Text);
neck = Convert.ToDouble(TBNeck.Text);
height = Convert.ToDouble(TBHeight.Text);
TBBodyFat.Text = Convert.ToString(String.Format("{0:p2}", ((501.5 / (1.0324 - .19077 * (Math.Log10(waist - neck)) + .15456 * (Math.Log10(height))) - 450) / 100)));
Error message
, , . , .
45.
waist = Convert.ToDouble(TBWaist.Text);