Calculate Your Age Using VB.NET

We often forgot to know what other people's age is. So now, in this tutorial, we will make a program entitled "Calculating age using VB.NET" So, now let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add one DateTimePicker named DateTimePicker1 to have input of our dates. Add one TextBox named TextBox1 that will serve as the display of our age. Add also a Button named Button1 so that we can use this calculating our age. Design your layout like this one below: design 3. Put this code for the Button1_Click. This will trigger to calculate your age.
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim yr As Integer = DateDiff(DateInterval.Year, DateTimePicker1.Value, Now)
  3.         Dim month As Integer = DateDiff(DateInterval.Month, DateTimePicker1.Value, Now) Mod 12
  4.         Dim day As Integer = DateDiff(DateInterval.Day, DateTimePicker1.Value, Now) Mod 30 - 10
  5.         TextBox1.Text = yr & " Years, " & month & " Months "
  6.     End Sub

Explanation:

We initialized yr to have the year difference between the present year and the year you were born as we code this syntax Dim yr As Integer = DateDiff(DateInterval.Year, DateTimePicker1.Value, Now) We initialized yr to have the month difference between the present month and the month you were born as we code this syntax Dim month As Integer = DateDiff(DateInterval.Month, DateTimePicker1.Value, Now) Mod 12. We find its remainder as code Mod 12 because it has 12 Months. Next, we put this code TextBox1.Text = yr & " Years, " & month & " Months " to display your age in the Textbox.

Output:

output Download the source code below and try it! :) For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Add new comment