chacoya121 Posted February 10, 2021 Posted February 10, 2021 Please help calculate the secs variable i can't get it right after 60s, it go into -1 and on.... Func CountDown() Local $count = 5 Local $newcount = $count * 60 ; 300 sec Local $time = TimerInit() While 1 Sleep(1000) Local $timediff = TimerDiff($time)/1000 ; turn into sec Local $mins= Floor(($newcount - $timediff)/60) Local $secs = Floor($newcount/$count - $timediff); Need help this line can't calculate after 60s ToolTip("Mins = " & $mins & " Secs = " & $secs) WEnd EndFunc
Moderators JLogan3o13 Posted February 10, 2021 Moderators Posted February 10, 2021 Moved to the appropriate forum. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Musashi Posted February 10, 2021 Posted February 10, 2021 A Google search for "AutoIt Countdown" returns multiple matches, so why reinvent the wheel. Here an example from @BrewManNH - extended with _Terminate(): #include "date.au3" HotKeySet("{ESC}", "_Terminate") Global $aTimeLeft Global $Seconds = 300 ; seconds in 5 minutes Global $hTimer = TimerInit() $aTimeLeft = _TimeConvert($Seconds) ; convert the seconds into an array holding the D:H:M:S ToolTip("Days: " & $aTimeLeft[0] & " Hours: " & $aTimeLeft[1] & " Minutes: " & $aTimeLeft[2] & " Seconds: " & $aTimeLeft[3], Default, Default, "Time Left") ; Display the converted seconds in a tooltip While $Seconds If TimerDiff($hTimer) >= 1000 Then ; if a second or more has passed then process these commands $aTimeLeft = _TimeConvert($Seconds) ; convert the seconds into an array holding the D:H:M:S $Seconds -= 1 ; subtract a second from the countdown ToolTip("Days: " & $aTimeLeft[0] & " Hours: " & $aTimeLeft[1] & " Minutes: " & $aTimeLeft[2] & " Seconds: " & $aTimeLeft[3], Default, Default, "Time Left") ; Display the converted seconds in a tooltip $hTimer = TimerInit() ; reset the timer handle EndIf WEnd ToolTip("") Func _TimeConvert($iSeconds) Local $aTimeSplit[4] $aTimeSplit[0] = Int($iSeconds / 86400) $aTimeSplit[1] = Int(($iSeconds - ($aTimeSplit[0] * 86400)) / 3600) $aTimeSplit[2] = Int((($iSeconds - ($aTimeSplit[0] * 86400)) - ($aTimeSplit[1] * 3600)) / 60) $aTimeSplit[3] = Int(((($iSeconds - ($aTimeSplit[0] * 86400)) - ($aTimeSplit[1] * 3600) - ($aTimeSplit[2] * 60)) * 60) / 60) Return $aTimeSplit EndFunc ;==>_TimeConvert Func _Terminate() ToolTip("") Exit EndFunc ;==>_Terminate "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Nine Posted February 10, 2021 Posted February 10, 2021 A more readable _TimeConvert function : Func _TimeConvert($iSeconds) Local Const $aDiv = [24, 60, 60] Local $aTimeSplit[4] For $i = UBound($aDiv) - 1 To 0 Step -1 $aTimeSplit[$i + 1] = Mod($iSeconds, $aDiv[$i]) $iSeconds = Floor($iSeconds / $aDiv[$i]) Next $aTimeSplit[0] = $iSeconds Return $aTimeSplit EndFunc ;==>_TimeConvert You can always make a better wheel Musashi 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now