im making a program that gives you the age of the person that enters there date of birth

the code i got at the moment is:

Private Sub Command1_Click()
Dim age As String
age = Month(Now) - Text4.Text
If age < 0 Then
age = 1
Else
age = 0
End If

Text3.Text = ""
Text3.Text = Text3.Text & "Name: " & Text1.Text & vbCrLf
Text3.Text = Text3.Text & "Gender: " & Text6.Text & vbCrLf
Text3.Text = Text3.Text & "Date of Birth: " & Format(Text2.Text, "##") & "/" & Format(Text4.Text, "##") & "/" & Format(Text5.Text, "####") & vbCrLf
Text3.Text = Text3.Text & "Age: " & (Year(Now) - Format(Text5.Text, "####")) - age & vbCrLf & vbCrLf
Text3.Text = Text3.Text & "Age in Months: " & ((Year(Now) - Format(Text5.Text, "####")) - age) * 12 + Text4.Text & vbCrLf
Text3.Text = Text3.Text & "Age in Weeks: " & Int(((Year(Now) - Text5.Text) * 52) + (((Month(Now) - 1) - Text4.Text) * 4)) & vbCrLf
End Sub

Private Sub Text6_Change()
Text6.Text = UCase(Text6.Text)
TicketClass = Text6.Text

Select Case TicketClass
Case "F"
Text6.Text = "Femail"
Class = True
Case "M"
Text6.Text = "Male"
Class = True
End Select
End Sub

i need to know if this is right and what i can do for the days hours minuets seconds etc.

I'm making my script cleaner
this is what i got so far

Private Sub Command1_Click()
Dim age As String

Dim yearold As String
Dim monthold As String
Dim dayold As String

Dim yearDOB As String
Dim monthDOB As String
Dim dayDOB As String

age = Month(Now) - Text4.Text
If age < 0 Then
age = 1
Else
age = 0
End If

dayDOB = Int(Text2.Text)
monthDOB = Int(Text4.Text)
yearDOB = Int(Text5.Text)

yearold = ((Year(Now) - yearDOB) - age)
monthold = (Month(Now) - 1) - monthDOB

Text3.Text = ""
Text3.Text = Text3.Text & "Name: " & Text1.Text & vbCrLf
Text3.Text = Text3.Text & "Gender: " & Text6.Text & vbCrLf
Text3.Text = Text3.Text & "Date of Birth: " & dayDOB & "/" & monthDOB & "/" & yearDOB & vbCrLf
Text3.Text = Text3.Text & "Age: " & yearold & vbCrLf & vbCrLf
Text3.Text = Text3.Text & "Age in Months: " & yearold * 12 + monthDOB & vbCrLf
Text3.Text = Text3.Text & "Age in Weeks: " & (yearold * 52) + (monthold * 4) & vbCrLf
Text3.Text = Text3.Text & "Age in Days: "
End Sub

Private Sub Text6_Change()
Text6.Text = UCase(Text6.Text)
TicketClass = Text6.Text

Select Case TicketClass
Case "F"
Text6.Text = "Female"
Class = True
Case "M"
Text6.Text = "Male"
Class = True
Case "M" Or "F"
Text6.Text = ""
End Select
End Sub


I'm going to change the scripting some more and post back with it.

MY new code:

Private Sub Command1_Click()
Dim age As String

Dim yearold As String
Dim monthold As String
Dim weekold As String
Dim dayold As String
Dim hourold As String
Dim minuteold As String
Dim secondold As String

Dim yearDOB As String
Dim monthDOB As String
Dim dayDOB As String
Dim DOB As String

age = Month(Now) - Text4.Text
If age < 0 Then
age = 1
Else
age = 0
End If

dayDOB = Int(Text2.Text)
monthDOB = Int(Text4.Text)
yearDOB = Int(Text5.Text)
DOB = dayDOB + "/" + monthDOB + "/" + yearDOB

yearold = DateDiff("yyyy", DOB, Now)
monthold = DateDiff("m", DOB, Now)
weekold = DateDiff("w", DOB, Now)
dayold = DateDiff("d", DOB, Now)
hourold = DateDiff("h", DOB, Now)
minuteold = DateDiff("n", DOB, Now)
secondold = DateDiff("s", DOB, Now)

Text3.Text = ""
Text3.Text = Text3.Text & "Name: " & Text1.Text & vbCrLf
Text3.Text = Text3.Text & "Gender: " & Text6.Text & vbCrLf
Text3.Text = Text3.Text & "Date of Birth: " & DOB & vbCrLf
Text3.Text = Text3.Text & "Age: " & yearold & vbCrLf & vbCrLf
Text3.Text = Text3.Text & "Age in Months: " & monthold & vbCrLf
Text3.Text = Text3.Text & "Age in Weeks: " & weekold & vbCrLf
Text3.Text = Text3.Text & "Age in Days: " & dayold & vbCrLf
Text3.Text = Text3.Text & "Age in Hours:" & hourold & vbCrLf
Text3.Text = Text3.Text & "Age in Minutes: " & minuteold & vbCrLf
Text3.Text = Text3.Text & "Age in Seconds: " & secondold & vbCrLf
End Sub

Private Sub Text6_Change()
Text6.Text = UCase(Text6.Text)
TicketClass = Text6.Text

Select Case TicketClass
Case "F"
Text6.Text = "Female"
Class = True
Case "M"
Text6.Text = "Male"
Class = True
End Select
End Sub

why you don't use datediff?
for more information goto msdn

im been and done this one.
it works well

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.