Results 1 to 3 of 3

Thread: simple IF statement

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    simple IF statement

    bit of a slow day!

    I want to check if:

    textbox1 or textbox2 length == 0 AND IF checkbox1 OR checkbox2 is checked then validation has failed


    how can I do this?

    This doesnt work:

    if (this.textbox1.Length == 0 || this.textbox2.Length == 0 && this.checkbox1.Checked || this.checkbox2.Checked)
    {
    //validation failed.
    }

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: simple IF statement

    Do you know what order those logical operators are going to be evaluated in? If you want to control the order of evaluation then use parentheses, just like a mathematical equation.

    Also, the TextBox class doesn't have a Length property. It would have to be either TextLength or Text.Length.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: simple IF statement

    sorry yes you are right (i was just typing it in here). And managed to solve it after I posted lol
    Thanks jm

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width