Age Calculator

Recommended Posts

Well, it took me a while, but I finally figured this out. Its an age calculator!

It gives you your current age, Months alive, Days alive, Hours alive, and how old you are in dog. *1

All credit goes to Jardenix (JustinReno)

Source: *2

```\$BirthString = InputBox("Age", "Please enter your birthstring:" & @CRLF & "(Numical Month/Day/4 Digit Year)")

MsgBox(0, _Month(), "Age: " & _Oldness() & @CRLF & "Months Alive: " & _MonthsAlive() & @CRLF & "Days Alive: " & _DaysAlive() & @CRLF & "Hours Alive: " & _HoursAlive() & @CRLF & _DogYears() & " dog years old.")

Func _Month()
Dim \$Months[2][12] = [["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], ["31", "29", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31"]]
\$Age = StringSplit(\$BirthString, "/")
\$MonthBorn = \$Months[0][\$Age[1] - 1]
Return \$MonthBorn
EndFunc

Func _Oldness()
\$Age = StringSplit(\$BirthString, "/")
If \$Age[1] > @MON Then \$Oldness = (@YEAR - \$Age[3]) - 1
If \$Age[1] < @MON Then \$Oldness = @YEAR - \$Age[3]
Return \$Oldness
EndFunc

Func _MonthsAlive()
\$Age = StringSplit(\$BirthString, "/")
\$MonthsLeft = 12 - \$Age[1]
\$MonthsAlive = \$Age[3] / 12 - \$MonthsLeft
Return Floor(\$MonthsAlive) - 1
EndFunc

Func _DaysAlive()
\$MonthsAlive = _MonthsAlive()
\$DaysAlive = \$MonthsAlive * 365 - 9993
Return \$DaysAlive
EndFunc

Func _HoursAlive()
\$DaysAlive = _DaysAlive()
\$HoursAlive = \$DaysAlive * 24 + 9993
Return \$HoursAlive
EndFunc

Func _DogYears()
\$Age = StringSplit(\$BirthString, "/")
\$DogYears = (@YEAR - \$Age[3]) / 7
Return \$DogYears
EndFunc```

Edit: Made how old you are in years 100% accurate.

*1: The numbers returned are estimated and not exact.

*2: The magic number 9993 makes the Days/Hours alive more accurate.

Edited by Jardenix
Share on other sites

Got this error:

C:\Users\Andreas\Desktop\dogyear.au3 (8) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

\$MonthBorn = \$Months[0][\$Age[1] - 1]

\$MonthBorn = ^ ERROR

when inputed my age (05231990)

Broken link? PM me and I'll send you the file!

Share on other sites

This is how you put you birthday into the inputbox:

(Numical Month/Day/4 Digit Year)

Example: 12/15/1973

Remember "/"

Edited by Jardenix
Share on other sites

How many weeks and estimated death day would make it better

Share on other sites

Tells what weekday you were born on!

```\$Month= 3
\$Day = 24
\$Year = 1991

MsgBox(0, "", CalcWeekday(\$Month,\$Day,\$Year))

Func CalcWeekday(\$Month,\$Day,\$Year,\$Cal=0)
\$a = Floor((14 - \$month) / 12)
\$y = \$year - \$a
\$m = \$month + 12*\$a - 2
\$gregorian = Mod(\$day + \$y + Floor(\$y/4) - Floor(\$y/100) + Floor(\$y/400) + Floor((31*\$m)/12),7);gregorian
\$julian = Mod(5 + \$day + \$y + Floor(\$y/4) + Floor((31*\$m)/12),7);julian
If \$Cal = 0 Then
\$Num = Floor(\$gregorian)
Else
\$Num =Floor(\$julian)
EndIf
Dim \$Day[7] = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
Return \$Day[\$Num]
EndFunc```
Share on other sites

Cool Paulie! How did you figure that out?!

Share on other sites

I could also do this: (Same as Paulie's function, but shorter..)

```Global \$Days[7] = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
Global \$Day = 18, \$Year = 94
\$V = Mod(Floor((\$Day + 2 + (10 * \$Year) / 8 + 10)), 7)
MsgBox(0, "", \$Days[\$V])```
Share on other sites

I think something is wrong with this: 2.714... dog years old. And I'm 19... Aren't dog years roughly 7 per human year?

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Share on other sites

No, its dog years in human form (If that makes sense).

If the dog is 2.7 years old, it would be 19 years old in dog years.

Share on other sites

Fun script.

Only one thing: Try to set your clock to your birthday and run the script again

Func _Oldness()

\$Age = StringSplit(\$BirthString, "/")

If \$Age[1] > @MON Then \$Oldness = (@YEAR - \$Age[3]) - 1

If \$Age[1] < @MON Then \$Oldness = @YEAR - \$Age[3]

Return \$Oldness

EndFunc

This piece of code does not calculate when your birthmonth = @MON, but only when larger or smaller.

You could use this:

(Although I'm not sure about the else statement's correctness)

Func _Oldness()

\$Age = StringSplit(\$BirthString, "/")

If \$Age[1] > @MON Then

\$Oldness = (@YEAR - \$Age[3]) - 1

ElseIf \$Age[1] < @MON Then

\$Oldness = @YEAR - \$Age[3]

Else

\$Oldness = @YEAR - \$Age[3]

EndIf

Return \$Oldness

EndFunc

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Share on other sites

No, its dog years in human form (If that makes sense).

If the dog is 2.7 years old, it would be 19 years old in dog years.

I don't really understand that and also thought the dog script was off it is roughly 7 years per year of our life, the dog won't be 19 when you are 19.

Edited by JellyFish666
Share on other sites

I corrected the dog years (check http://www.onlineconversion.com/dogyears.htm for the forumla)

```\$BirthString = InputBox("Age", "Please enter your birthstring:" & @CRLF & "(Numical Month/Day/4 Digit Year)")

MsgBox(0, _Month(), "Age: " & _Oldness() & @CRLF & "Months Alive: " & _MonthsAlive() & @CRLF & "Days Alive: " & _DaysAlive() & @CRLF & "Hours Alive: " & _HoursAlive() & @CRLF & _DogYears() & " dog years old." & @CRLF & "If you are a dog this is your age : " & _CorrectDogYears())

Func _Month()
Dim \$Months[2][12] = [["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], ["31", "29", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31"]]
\$Age = StringSplit(\$BirthString, "/")
\$MonthBorn = \$Months[0][\$Age[1] - 1]
Return \$MonthBorn
EndFunc

Func _Oldness()
\$Age = StringSplit(\$BirthString, "/")
If \$Age[1] > @MON Then \$Oldness = (@YEAR - \$Age[3]) - 1
If \$Age[1] < @MON Then \$Oldness = @YEAR - \$Age[3]
Return \$Oldness
EndFunc

Func _MonthsAlive()
\$Age = StringSplit(\$BirthString, "/")
\$MonthsLeft = 12 - \$Age[1]
\$MonthsAlive = \$Age[3] / 12 - \$MonthsLeft
Return Floor(\$MonthsAlive) - 1
EndFunc

Func _DaysAlive()
\$MonthsAlive = _MonthsAlive()
\$DaysAlive = \$MonthsAlive * 365 - 9993
Return \$DaysAlive
EndFunc

Func _HoursAlive()
\$DaysAlive = _DaysAlive()
\$HoursAlive = \$DaysAlive * 24 + 9993
Return \$HoursAlive
EndFunc

Func _DogYears()
;~     \$Age = StringSplit(\$BirthString, "/")
;~     \$DogYears = (@YEAR - \$Age[3]) / 7
;~     Return \$DogYears
\$a = _Oldness()
\$b = Number("10,500000000000000002625")
Return \$a / \$b
EndFunc

Func _CorrectDogYears()
\$1 = 0
For \$i = 1 To _Oldness()
If \$i <= 2 Then
\$1 += 1 * 10.5
ConsoleWrite("<2 = " & \$1 & @CRLF)
Else
\$1 += 1 * 4
ConsoleWrite(">2 = " & \$1 & @CRLF)
EndIf
Next
Return \$1
EndFunc```
Share on other sites

What the hell kind of UDF relies on global variables? You need to be passing the birthdate as a parameter.

Also I'm going to say the same thing I tell everyone else.

You cannnot perform math on dates in AutoIt, this is not PHP. See _DateDiff().

I enter 1/1/2008 and here is what it shows:

Age: -1

Months Alive: 155

Days Alive: 46582

Hours Alive: 1127961

0 dog years old

Again with 1/1/2007:

Age: 0

Months Alive: 155

Days Alive: 46852

Hours Alive: 1127961

0.142857142857143 dog years old

Share on other sites

This is not a UDF WeaponX. Get over it. There are no Global variables in my script. The dog years function is correct,

The function takes your birthdate, divides it by seven to get how old you are if you were a dog (In human years)(NOT Dog years.)

Edited by Jardenix
Share on other sites

The dog years function is correct,

The function takes your birthdate, divides it by seven to get how old you are if you were a dog (In human years)(NOT Dog years.)

I think it would be much more applicable/understandable if you were just told you many dog years you've been alive rather than supposing you are a dog that's lived x amount of years and wondering how many human years you've lived. Just my opinion though... Edited by Achilles
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Share on other sites

This is not a UDF WeaponX. Get over it. There are no Global variables in my script. The dog years function is correct,

The function takes your birthdate, divides it by seven to get how old you are if you were a dog (In human years)(NOT Dog years.)

Dude. You define \$BirthString using InputBox() and it is not passed to any of your functions, therefore it is Global. I am not trying to give you a hard time, its just proper coding.

Share on other sites

• 1 year later...

Hey you , I dont want to know all those details about my age. I am trying to forget it.

Share on other sites

• Developers

Hey you , I dont want to know all those details about my age. I am trying to forget it.

Seriously, stop resurrecting posts that are a couple of years old with BS comments like this!

Jos

Live for the present,
Dream of the future,
Learn from the past.

Create an account

Register a new account

• Recently Browsing   0 members

×

• Wiki
• AutoIt Resources

• FAQ
×
• Create New...