Age generator in VB6

In this tutorial, it shows you on how to generate age using Visual Basic 6.0. 

Instructions:

  1. Add component Windows Common Control 6.0
  2. Add DTPicker control to you form layout.
  3. Add Button control change the name to cmdGenerate.
  4. Inside the cmdGenerate event write a code (see code snippet below)
  5. 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