Instructions:
- Add component Windows Common Control 6.0
- Add DTPicker control to you form layout.
- Add Button control change the name to cmdGenerate.
- Inside the cmdGenerate event write a code (see code snippet below)
- Run the program to see the output.
Code snippet
Private Sub cmdGenerate_Click()
Dim iyears As Integer
Dim tmonth As Integer
Dim Bmonth As Integer
iyears = DateDiff("yyyy", "01/01/" & DatePart("yyyy", DTPicker1.Value), _
"01/01/" & DatePart("yyyy", Now)) - 1
tmonth = DatePart("m", Now)
Bmonth = DatePart("m", DTPicker1.Value)
Select Case tmonth
Case Is > Bmonth
iyears = iyears + 1
Case Is = Bmonth
If DatePart("d", DTPicker1.Value) <= _
DatePart("d", Now) Then iyears = iyears +
End Select
lblAge.Caption = "Your age is " & iyears
End Sub
Screenshot