ProblemYou want to check a year to see if it's a leap year. SolutionUse the shared IsLeapYear() function provided by the Date object to test any year. DiscussionThe IsLeapYear() function returns true if the year passed to it is a leap year and False if it isn't. The following code provides a working demonstration showing how to call this shared function to test the current year: Dim leapYear As Boolean = Date.IsLeapYear(Now.Year) MsgBox(String.Format( _ "{0} is a leap year: {1}", Now.Year, leapYear)) Figure 7-22 shows the results as displayed by the message box. Figure 7-22. The Date.IsLeapYear function reveals instantly that 2005 is not a leap yearBecause the IsLeapYear() function is a shared function, you must call it directly from the Date object, not from an instance of a Date. |