How to Calculate Age using VB.Net


This tutorial is all about How to Calculate Age using VB.Net. With this tutorial you can Calculate Age using VB.Net. easily. So let’s get started:

  • First is open the Visual Basic, Select File on the menu, then click New and create a new project.

  • Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK

  • Design your form like this just like what I’ve shown you below.
    Add a Label, 4 Textbox, and a Button.

  • After Designing your form, Add this code to the button.
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. Dim a As String
    3. Dim b As String
    4. Dim c As String
    5. a = TextBox3.Text
    6. b = TextBox1.Text
    7. c = TextBox2.Text
    8. Dim DOB As New DateTime(a, b, c)
    9. Dim Years As Integer = DateDiff(DateInterval.Year, DOB, Now) - 1
    10. Dim Months As Integer = DateDiff(DateInterval.Month, DOB, Now) Mod 12
    11. Dim days As Integer = DateDiff(DateInterval.Day, DOB, Now) Mod 30 - 10
    12. TextBox4.Text = Years & " Years, " & Months & " Months "
    13. End Sub


  • Finally, Click F5 to run Program.

If you have any comments or suggestion about on How to Calculate Age using VB.Net, Please Feel Free to contact our webpage.

Download How to Calculate Age using VB.Net Code Here

Other articles you might read also:



Facebook Comments


Please enter your comment!
Please enter your name here