Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if statement (textbox equals 0)

Status
Not open for further replies.

pinkpoppy

Programmer
Jul 6, 2011
75
US
I have an if statement that says this:

if abc.text is greater than or equal to xyz.text, then lblerrormessage.text and lblabc.text shows error messages, else lblerrormessage and lblabc shows nothing.

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

Code:
            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 = "";
            }

Any help is appreciated! Thanks.
 
Have you tried using compare validators and required field validators?
 
You could try something like this. However, I suggest using TryParse instead to avoid possible errors.
Code:
var abc = Convert.ToDouble(abc.Text);
var zyx = Convert.ToDouble(xyz.Text)
if (abc >= xyz) 
{  
   if( abc != 0 && xyz !=0)
   { 
      lblerrorMessage.Text = "Please correct the following:"; 
      lblabc.Text = "Must be less than."; 
      return; 
   }
} 
else { 
   lblerrorMessage.Text = ""; lblabc.Text = ""; 
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top