I am a newbie to C# and I am getting error messages because of a simple if statement. I am trying out my skills with a simple alarm clock, and I have 3 nested If Statments and it is giving me an error. here is the code I am using. It is making sure that three variables, hour, minute, second are all valid (between 1-12 for hour, 1-59 for minute). Here is the code I used:
private void SetButton_Click(object sender, EventArgs e)
{
hour = Convert.ToInt32(textBox1.Text);
hour = int.Parse(textBox1.Text);
if (hour <= 12 && hour < 0){
minute = Convert.ToInt32(textBox2.Text);
minute = int.Parse(textBox2.Text);
if(minute <= 59){
second = Convert.ToInt32(textBox3.Text);
second = int.Parse(textBox3.Text);
if(second >= 0 && <= 59){
goto timer;
else if(second >= 60 || second < 0){
textBox3.Text = "Between 0 and 59";
}
}
else if(minute >= 60 || minute < 0) {
textBox2.Text = "Between 0 and 59";
}
}
else if(hour < 1 || hour > 12) {
textBox1.Text = "between 1 and 12";
}
}
}
I have included a link to the ZIP file of my project so you can debug it and run it in context:
Click Here

2 answers
Try the following:
However, this code will still throw an exception if any of the textboxes don't contain an integer.
You can deal with this by replacing this line:
with this:
and with similar changes to the code which parses out minutes and seconds.
The int.TryParse method returns false if it's first argument (a string) is not an integer and sets the second argument (preceded by 'out') to zero.
Otherwise, it returns true and sets the second argument to the integer which is arrived at when the first argument is parsed.
answered one year ago by:
17279
107
I made the changes you asked for but I still am getting errors. The updated zip file is here (https://docs.google.com/leaf?id=0B89GBk8q-FkkNzIyYjY2OTQtNWU2MC00ZWFjLTk5NzctZjgxYzYzOWZiMWI3&hl=en)
107
If you fix it I would like you to send the entire code of the program.cs file or zip it for me.
All that appears to be wrong is that you have some brackets in the wrong place.
The Form class should look like this:
answered one year ago by:
17279