Results 1 to 5 of 5

Thread: [RESOLVED] Simple IF statement question

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    48

    Resolved [RESOLVED] Simple IF statement question

    Hi,

    I have a simple IF statement.

    If a condition is true then I want to inform the user so that they can fix it and in effect break out of the statement.

    I currently have this

    Code:
    if (cmbChildName.Text == "")
                {
                    MessageBox.Show("Please select a childs name");
                }
    But the code continues and doesn't break it just carrys on after OK is clicked on the Message Box.

    I want the user to be able to correct the problem..

    In VB I would have used Exit Sub.

    Many thanks

    Mark

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Simple IF statement question

    else

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    48

    Re: Simple IF statement question

    Yes, but that won't 'break it out'

    Here is my code. After checking the first combo box it warns the user, but it also continue to check the second. I want it to warn the user and then stop/exit/break...

    Code:
    //check if childs name and month have been selected
                if (cmbChildName.Text == "")
                {
                    MessageBox.Show("Please select a childs name");
                }
    
                if (cmbMonth.Text == "")
                {
                    MessageBox.Show("Please select a month");
                }
                //show each of the controls
                foreach (Control ctrl in this.Controls)
                {
                    ctrl.Visible = true;
                }
                //disable combos
                cmbMonth.Enabled = false;
                cmbChildName.Enabled = false;

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Simple IF statement question

    Code:
    //check if childs name and month have been selected
    if (cmbChildName.Text == "")
    {
        MessageBox.Show("Please select a childs name");
    }
    else if (cmbMonth.Text == "")
    {
        MessageBox.Show("Please select a month");
    }
    else
    {
        //show each of the controls
        foreach (Control ctrl in this.Controls)
        {
            ctrl.Visible = true;
        }
        
        //disable combos
        cmbMonth.Enabled = false;
        cmbChildName.Enabled = false;
    }

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    48

    Re: Simple IF statement question

    Doh.... that simple!!!!

    Thank you

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