Jump to content

Have a function return an array without defining it beforehand


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

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