Jump to content

Recommended Posts

Posted (edited)

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.

Please leave a comment!

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

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

Edited by Jardenix
Posted

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!

Posted (edited)

This is how you put you birthday into the inputbox:

(Numical Month/Day/4 Digit Year)

Example: 12/15/1973

Remember "/"

Edited by Jardenix
Posted

Add this!

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
Posted

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])
Posted

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)

Posted (edited)

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
Posted

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
Posted

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

Posted (edited)

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
Posted (edited)

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]
Posted

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.

  • 1 year later...
  • Developers
Posted

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...