Validate Leap Year in VB.NET Console

In this tutorial, i will teach you how to validate a year as leap year or not. Hence we already know that leap year has 366 days instead of the normal 365 days. Leap years occur every 4 years. And this fact is our formula in finding a leap year using the console application in vb.net. Now, let's start this tutorial! 1. Let's start with creating a Console Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Console Application. 2. Name your project as LeapYear as your module. Note: This is a console application so we cannot have visual controls for this tutorial. 3. Add the following code in your module.
  1. Module LeapYear
  2.     Sub main()
Initialize variable yeear as Integer and make it input as your inputted year.
  1.         Dim yeaar As Integer
  2.         Console.Write("Enter Year:")
  3.         yeaar = CInt(Console.ReadLine())
Make an If Else Statement because we all know that leap year has an exception that every 100 years special rules apply and will be a leap year. For example 1900 was not a leap year, but 2000 was. We used the Mod operator to find the remainder of your inputted year divided by 100 that is not equal to 0. Then, after that filter again the year that a leap year will occur in every 4 years because of February 29. Otherwise, it is not a leap year.
  1.  
  2.         If yeaar Mod 100 <> 0 Then
  3.             If yeaar Mod 4 = 0 Then
  4.                 Console.WriteLine(yeaar & " is a Leap year")
  5.             Else
  6.                 Console.WriteLine(yeaar & " is NOT a Leap year")
  7.             End If
Next, if 100 multiplied by 4 years and that is 400 it will be a leap year. Otherwise, not. This is an else statement that is not equal to the 100 years that leap years special rule is applied.
  1.         Else
  2.             If yeaar Mod 400 = 0 Then
  3.                 Console.WriteLine(yeaar & " is a Leap year")
  4.             Else
  5.                 Console.WriteLine(yeaar & " is NOT a Leap year")
  6.             End If
  7.         End If
  8.         Console.ReadLine()
  9.     End Sub
  10. End Module
Output: output Best Regards, Engr. Lyndon R. Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer If you have some queries, feel free to contact the number or e-mail below. Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Visit and like my page on Facebook at: https://www.facebook.com/BermzISware Add and Follow me on Facebook: https://www.facebook.com/donzzsky

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment