| | |
VB6 age calculator
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Aug 2009
Posts: 30
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Aug 2009
Posts: 30
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Aug 2009
Posts: 30
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Creating User Manual in Vb6 and Populating TreeView from Mysql database VB6 (Visual Basic 4 / 5 / 6)
- Code Snippet: Console calculator Part 3 : The calculator engine (C#)
- Age of Aquarius (Geeks' Lounge)
- age calculator (Computer Science)
- Age Calculator (C)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: VB6 and Shell
- Next Thread: Pyramid Issue
| Thread Tools | Search this Thread |
6 age amd avatar ban basic beginner birth bluegene button c++ calculator cd chips class code computer convert creat database date date/time datepart development dos drawing economy energy enterprise faceparty form format gdi+ generator graph hardware ibm ibm.news intelibm keypress law linux loan medicine memory microsoft mysql news openoffice opensource operating-system pc php ps3 python readfile recession redhat russia sex simple staticmembers string sun supercomputer supercomputing technology time trends ubuntu vb vb6 visual visualbasic visualbasic6 web working x86 year






