Saturday, 8 December 2012

Check for Leap year in VB.NET


Check for Leap year in VB.NET

How to determine whether a year is a leap year

To determine whether a year is a leap year, follow these steps:
  1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
  2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
  3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
  4. The year is a leap year (it has 366 days).
  5. The year is not a leap year (it has 365 days).
VB.NET Code

       Public Function isLeapYear(ByVal year As Integer) As Boolean
            Dim isLeap As Boolean =  True 
            If year % 4 = 0 Then
                If year % 100 = 0 Then
                 If year % 400 = 0 Then
                     Console.WriteLine("{0} is Leap Year", year)
                 End If
                Else If "{0} is Leap Year",year Then 
                End If
 
 
            Else 
                Console.WriteLine("{0} is not Leap Year", year)
                isLeap = False
            End If
 
            Return isLeap
       End Function


No comments:

Post a Comment