[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
Re: Simple IF statement question
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;
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;
}
Re: Simple IF statement question
Doh.... that simple!!!!
Thank you