|
-
Jul 20th, 2010, 02:46 AM
#1
Thread Starter
New Member
A coding question
Hey guys. This is my first post here. I'm new to Visual Basic, just taking an introductory course that gets the basics out of the way. I just completed and turned in a project that left me with a concern. The assignment was to program Zeller's Congruence, basically an algorith that which, if you pass it a day of month, month, and year, it returns to you the day of the week that date occurred on.
The assignment only called the algorithm to be correctly coded. However, I decided to go a little beyond the scope of the problem statement and put in some error checking. For instance, I wanted to make sure that when passing values in for the days of the month, only reasonable values would be placed (between 1-31 for most months, 1-30 for others, and of course 1-29 for February during leap years)
Here's a snippet of my code (the entire thing is very long)
Code:
If MonthNumber = 13 Or MonthNumber = 3 Or MonthNumber = 5 Or MonthNumber = 7 Or MonthNumber = 8 Or MonthNumber = 10 Or MonthNumber = 12 Then
If DayValue <= 0 Or DayValue > 31 Then
MessageBox.Show("This month can only have between 1-31 days! Please re-enter day", "Data Entry Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
With DayTextBox
.Focus()
.SelectAll()
End With
End If
End If
So for this condition, I'm testing the months that end in 31 days and checking to see that if the user inputs a day value greater than 31, to return an error.
My problem is this. Although I successfully return the error, the program will continue to send the values to the algorithm and calculate a value. Once the user hits the ok button on the message box, a day value is returned for a date that does not exist. How do I prevent the code from executnig once the error occurs. I don't want a value returned for input data that makes no sense.
Thanks
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
|