943,691 Members | Top Members by Rank

Ad:
Sep 5th, 2009
0

VB6 age calculator

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
drabsch is offline Offline
35 posts
since Aug 2009
Sep 5th, 2009
0

Re: VB6 age calculator

Use DateDiff. Check this out.
Reputation Points: 13
Solved Threads: 2
Light Poster
Seba Sama is offline Offline
29 posts
since Jul 2006
Sep 8th, 2009
0

Re: VB6 age calculator

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
drabsch is offline Offline
35 posts
since Aug 2009
Sep 8th, 2009
0

Re: VB6 age calculator

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
Reputation Points: 10
Solved Threads: 0
Light Poster
drabsch is offline Offline
35 posts
since Aug 2009
Sep 17th, 2009
0

Re: VB6 age calculator

why you don't use datediff?
for more information goto msdn
Reputation Points: 10
Solved Threads: 10
Junior Poster in Training
omoridi is offline Offline
72 posts
since Sep 2009
Sep 17th, 2009
0

Re: VB6 age calculator

im been and done this one.
it works well
Reputation Points: 10
Solved Threads: 0
Light Poster
drabsch is offline Offline
35 posts
since Aug 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB6 and Shell
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Pyramid Issue





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC