PDA

Click to See Complete Forum and Search --> : [RESOLVED] Simple IF statement question


Mr_Floyd1976
Jun 13th, 2007, 04:37 PM
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


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

penagate
Jun 13th, 2007, 04:45 PM
else

Mr_Floyd1976
Jun 13th, 2007, 04:48 PM
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...


//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;

penagate
Jun 13th, 2007, 04:51 PM
//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;
}

Mr_Floyd1976
Jun 13th, 2007, 04:54 PM
Doh.... that simple!!!!

Thank you