PROGRAMMING EXERCISE
Date Validation
Write a program that determines whether a date entered by the user is valid. The user should enter numbers for the month, day, and 4-digit year as separate values. When the user presses the "Check" button, display a message in a Label indicating whether or not the date is valid.
The rules to validate a date are as follows:
(1) The month must be a number between 1 and 12.
(2) If the month number indicates April, June, September, or November, then the day value must be between 1 and 30.
(3) If the month number indicates any other month except February, then the day value must be between 1 and 31.
(4) If the month number indicates February, then the year must be checked to see if it is a leap year. A year is a leap year if the following conditions are met: If the year is evenly divisible by 100, then it must also be evenly divisible by 400 to be considered a leap year (i.e. 1600 and 2000 are leap years; 1700, 1800, and 1900 are not); otherwise, if the year is evenly divisible by 4, then it is a leap year. If it is a leap year, the day value must be between 1 and 29; otherwise, the day value must be between 1 and 28.
Notes:
· Set the MaxLength property of the Month and Day textboxes to 2 and set the MaxLength property of the Year textbox to 4. Make sure the user enters only numbers in these textboxes.
· If you determine early on in the checking process that the date is not valid, you can exit the Check button's event procedure early by using the Exit Sub statement. (For example, if you determine that the month is not valid, there is no need to check the day.)
· After checking the date, if you determine that a date is not valid, set focus to the Month textbox, otherwise set focus to the Clear button.
· Do not use Date variables for this program and do not use any Date-specific functions. (That would take away all the fun!)
Sample runs of the program might look like the following:
Download the solution for this project here.