Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Calculate Age - Visual Basic .

NET
For This Project you need 4 TextBoxes and 1 Button

TextBox1 will be used to enter the month of birth


TextBox2 will be used to enter the day of birth
TextBox3 will be used to enter the year of birth
TextBox4 will be used to show the calculated age
Button1 will be used to calculate age after the user enters DOB
Below is the code for Button1.Click
?
1
2
3
4 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
5 Handles Button1.Click
Dim a As String
6
Dim b As String
7
Dim c As String
8
a = TextBox3.Text
b = TextBox1.Text
9
c = TextBox2.Text
1
Dim DOB As New DateTime(a, b, c)
0
Dim Years As Integer = DateDiff(DateInterval.Year, DOB, Now) - 1
11
Dim Months As Integer = DateDiff(DateInterval.Month, DOB, Now) Mod 12
1
Dim days As Integer = DateDiff(DateInterval.Day, DOB, Now) Mod 30 - 10
TextBox4.Text = Years & " Years, " & Months & " Months "
2
End
Sub
1
3
1
4

You might also like