Hi all I was working on a program and really need some help with my coding. Here is code I'm working on thanks for your advice in advance.
'this program will Display Year of age and days on earth assumming the current date is 12/31/2006, the user types 1980 into the txtBox before btnDisplay is clicked. The last two lines of the output should be displayed by one or more Sub Procedures using data passed by variables from an event procedure (You are now 26 years old, You have lived for more than 9490 days)

Dim yob As Integer

yob = txtBox.Text - 12 / 31 / 2006

AgeIn2006(yob)

End Sub

Sub AgeIn2006(ByVal yob As Integer)

'Displays the age in years and days

txtBox.Text = "You are " & yob & "years old you have lived for more than
" & yob * 365

End Sub

I was not sure how to tag or wrap my post, if I did it wrong again please advised me
of the correct way, trust me when I say I'm new to this. Didn't realize how frustrating coding was.

Recommended Answers

All 4 Replies

Hi Tank1970,
I hope there are many ways you can do. Here is one example

Dim curYear As Integer
Dim iAge As Integer
curYear = Format(Date, "YYYY")
iAge = curYear - txtBox.Text
MsgBox "You are " & iAge & " years old. You have lived for more than " & iAge * 365 & " days."

Hope this helps

Use the DateDiff Function to determine the interval between 2 dates or time.

Dim Bday as Date
Dim dVar as string, dAge as string

dAge = DateDiff("yyyy",bDay,Date) 'Shows your Age
dVar = DateDiff("d",bDay,Date)    'Shows # of Days between bDay and the Date

Try it. Hope it works for you.

Private Sub Command1_Click()
Dim curYear As Integer
Dim iAge As Integer
Dim i As Integer
curYear = Format(Date, "YYYY")
i = Format(Text1.Text, "yyyy")
iAge = curYear - i
MsgBox "You are " & iAge & " years old. You have lived for more than " & iAge * 365 & " days."
End Sub

this will really helps u....

Thanks all for your help. They were all good answers.

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.