Setting a Leap year condition
-
I have written a programme that should allow a pupil to enter his details and then the programme will display the pupil’s profile using a dialog box. I have worked the rest fine but I have difficulty in setting the leap year limits for the month of February. I have tried juggling around my code in many different ways, but seem not to get it right. I have left the code with an array of 10 leap years that I consider to fall within a pupil’s age. I definitely know that the problem is not with coding an array, it’s something else. I have said: For Leap year 1 To Leap year 10 If the month is "February" And CInt(The “Value” of numeric-up-down representing the pupil’s year of birth) <> Leap year And [Day is ("29") Or ("30") Or ("31")] Then ErrorMessage1 Exit Sub End If If the month is "February" And CInt(The “Value” of numeric-up-down representing the pupil’s year of birth) = Leap year And [Day is ("30") Or ("31")] Then ErrorMessage2 Exit Sub End If However, an error exist somehow in the code, may you give me an idea of where the problem is. Been always great to be part of this forum, especially when I know they know more than what I know…..
-
I have written a programme that should allow a pupil to enter his details and then the programme will display the pupil’s profile using a dialog box. I have worked the rest fine but I have difficulty in setting the leap year limits for the month of February. I have tried juggling around my code in many different ways, but seem not to get it right. I have left the code with an array of 10 leap years that I consider to fall within a pupil’s age. I definitely know that the problem is not with coding an array, it’s something else. I have said: For Leap year 1 To Leap year 10 If the month is "February" And CInt(The “Value” of numeric-up-down representing the pupil’s year of birth) <> Leap year And [Day is ("29") Or ("30") Or ("31")] Then ErrorMessage1 Exit Sub End If If the month is "February" And CInt(The “Value” of numeric-up-down representing the pupil’s year of birth) = Leap year And [Day is ("30") Or ("31")] Then ErrorMessage2 Exit Sub End If However, an error exist somehow in the code, may you give me an idea of where the problem is. Been always great to be part of this forum, especially when I know they know more than what I know…..
You might want to learn what the rules for leap years are: If the year is divisible by 4 then it's a leap year. However, if the year is also divisible by 100, then it is not, but it it's divisible by 400 then it is. Hence 2000, 2004, 2400 are leap years, but 1900 and 2100 are not. A leap year has one additional day, which is February 29th. ------------------ If you're using .NET, just use DateTime.Parse or something to see if the date entered is valid or not (as the DateTime APIs handle this stuff anyway, so you're better off using them). VB6 may have a similar API.
Ian Darling "One of the few systems...which has had “no deaths” in the reliability requirements." - Michael Platt