# If statement (textbox = 0) RSS

## 3 replies

Last post Feb 27, 2013 09:14 PM by Paul Linton

Member

6 Points

25 Posts

### If statement (textbox = 0)

I have an IF Statement that says this:

if abc.text is greater than or equal to xyz.text, then lblErrorMessage and lblabc will show a message, Else lblErrorMessage and lblabc shows nothing.

But sometimes abc.text and xyz will be 0 and thats fine. How do I write that?

```if (Convert.ToDouble(abc.Text) >= Convert.ToDouble(xyz.Text))
{
lblerrorMessage.Text = "Please correct the following:";
lblabc.Text = "Must be less than.";
return;
}
else
{
lblerrorMessage.Text = "";
lblabc.Text = "";
}```

All-Star

27896 Points

4618 Posts

### Re: If statement (textbox = 0)

You just need to change the greater-than-or-equals sign (>=) to simply be a greater-than sign (>) within your if-statement :

```//If "abc" is strictly greater than "xyz"
if (Convert.ToDouble(abc.Text) > Convert.ToDouble(xyz.Text))
{
lblerrorMessage.Text = "Please correct the following:";
lblabc.Text = "Must be less than.";
return;
}
else
{
//Otherwise things are fine
lblerrorMessage.Text = "";
lblabc.Text = "";
}```

Alternatively, you could actually check if both of the values were 0 (although the first solution should fit your needs) :

```double abc = Convert.ToDouble(abc.Text);
double xyz = Convert.ToDouble(xyz.Text);

//If "abc" is greater than or equal to "xyz" and abc and xyz are non-zero
if ((abc >= xyz) && (abc != 0 && xyz != 0))
{
lblerrorMessage.Text = "Please correct the following:";
lblabc.Text = "Must be less than.";
return;
}
else
{
//Otherwise things are fine
lblerrorMessage.Text = "";
lblabc.Text = "";
}```

Member

6 Points

25 Posts

Ok, thanks!

Star

13431 Points

2535 Posts