Sign in to follow this  
Followers 0
Zhelkus

Have a function return an array without defining it beforehand

5 posts in this topic

First off, I want to make it clear that I'm a perfect noob just in case my question sounds dumb. I'm making a UDF that'll convert the result returned from a Timer() function into a neat [seconds,minutes,hours,days] format.

Currently, I'm having trouble making the function return an array. How do I make it work? Here's the code:

Func TimerResultNeatify($timerresult)
    Local $seconds = 0
    Local $minutes = 0
    Local $hours = 0
    Local $days = 0
    
    $seconds = Round($timerresult / 1000)
    
    While $seconds > 60
        $seconds -= 60
        $minutes += 1
    WEnd
    While $minutes > 60
        $minutes -= 60
        $hours += 1
    WEnd
    While $hours > 24
        $hours -= 24
        $days += 1
    WEnd
    
    Return $seconds, $minutes, $hours, $days
EndFunc   ;==>TimerResultToTime

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi, I've not tested it

;$aTime[0] = seconds
;$aTime[1] = minutes
;$aTime[2] = hours
;$aTime[3] = days
Func TimerResultNeatify($timerresult)
    Local $aTime[4]

    $aTime[0] = Round($timerresult / 1000)
   
    While $aTime[0] > 60
        $aTime[0] -= 60
        $aTime[1] += 1
    WEnd
    While $aTime[1] > 60
        $aTime[1] -= 60
        $aTime[2] += 1
    WEnd
    While $aTime[2] > 24
        $aTime[2] -= 24
        $aTime[3] += 1
    WEnd
   
    Return $aTime
EndFunc   ;==>TimerResultToTime

Cheers

Edit: Corrected some errors, I think ..lol

Edited by smashly

Share this post


Link to post
Share on other sites

Awesome! Thanks a lot! It actually looks even tidier :D

Share this post


Link to post
Share on other sites

Looks similar to TicksToTime:

#Include <Date.au3>
_TicksToTime($iTicks, ByRef $iHours, ByRef $iMins,  ByRef $iSecs)

I don't think I should post this script in the Example Scripts forum because every script there seems to be "on a higher level" :D

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0