VB6 age calculator

Thread Solved

Join Date: Aug 2009
Posts: 30
Reputation: drabsch is an unknown quantity at this point 
Solved Threads: 0
drabsch drabsch is offline Offline
Light Poster

VB6 age calculator

 
0
  #1
Sep 5th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 23
Reputation: Seba Sama is an unknown quantity at this point 
Solved Threads: 1
Seba Sama Seba Sama is offline Offline
Newbie Poster

Re: VB6 age calculator

 
0
  #2
Sep 5th, 2009
Use DateDiff. Check this out.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 30
Reputation: drabsch is an unknown quantity at this point 
Solved Threads: 0
drabsch drabsch is offline Offline
Light Poster

Re: VB6 age calculator

 
0
  #3
Sep 8th, 2009
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.
Last edited by drabsch; Sep 8th, 2009 at 3:36 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 30
Reputation: drabsch is an unknown quantity at this point 
Solved Threads: 0
drabsch drabsch is offline Offline
Light Poster

Re: VB6 age calculator

 
0
  #4
Sep 8th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 57
Reputation: omoridi is an unknown quantity at this point 
Solved Threads: 8
omoridi omoridi is offline Offline
Junior Poster in Training

Re: VB6 age calculator

 
0
  #5
Sep 17th, 2009
why you don't use datediff?
for more information goto msdn
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 30
Reputation: drabsch is an unknown quantity at this point 
Solved Threads: 0
drabsch drabsch is offline Offline
Light Poster

Re: VB6 age calculator

 
0
  #6
Sep 17th, 2009
im been and done this one.
it works well
Reply With Quote Quick reply to this message  
Reply

Tags
age, birth, calculator, date, vb6

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC