|
-
Jun 13th, 2007, 04:37 PM
#1
Thread Starter
Member
[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
-
Jun 13th, 2007, 04:45 PM
#2
Re: Simple IF statement question
-
Jun 13th, 2007, 04:48 PM
#3
Thread Starter
Member
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;
-
Jun 13th, 2007, 04:51 PM
#4
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;
}
-
Jun 13th, 2007, 04:54 PM
#5
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|