VB.NET Program – Age Calculator : This program will explain to calculate age by entering Date of Birth and Current date. After entering date of birth and Current date it will display birth day in the date of birth datetime picker and current day will display in the till now date time picker. In the result label it will display age in years with month and days. This is developed in VB.NET works with a very simple logic.
VB.NET Program – Age Calculator
The above screenshot is the form design of the age calculator. This is designed with 3 labels, 2 date time picker and one submit button to calculate age. The date of birth, current date input and result everything works in the single form.
Source code: In the source code four variables created. Date of birth stores in datevalue1 and current date stores in datevalue2. After the substraction its result stores in datet. 3 different formulas used to calculate year, month and days. The difference stores in diff variable.
Public Class Form1 Dim datevalue1 As Date Dim datevalue2 As Date Dim datet As TimeSpan Dim diff As Double Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click datevalue1 = Me.DateTimePicker1.Value.ToShortDateString datevalue2 = Me.DateTimePicker2.Value.ToShortDateString datet = (datevalue2 - datevalue1) diff = datet.Days Me.Label3.Text = ("Your Age is " + Str(Int(diff / 365)) + " Year") diff = diff Mod 365 Me.Label3.Text = Me.Label3.Text + (Str(Int(diff / 30)) + " Month(s) ") diff = diff Mod 30 Me.Label3.Text = Me.Label3.Text + (Str(diff) + " Day(s)") End Sub End Class
Download Example Program: This example code of age calculator developed using Visual studio 2012 version and it works well in visual studio 2013.
Note: This is the mini student project you can submit it for your college seminar projects or semester projects. Coding is very simple and very easy to understand. If you still have doubts you can view this video tutorial which will explain the method to create this program: