Jump to content

Time Countdown


Recommended Posts

Hi everyone, I need help on making a counter. Anyone could help?

Thanks in advance.

#region OnRunCheck
If _Singleton("Timed Bomb",1) = 0 Then
    Exit
EndIf
#endregion OnRunCheck
#region Includes
#include<GUIConstants.au3>
#include<Misc.au3>
#NoTrayIcon
#endregion Includes
#region decalres
$Minute=1
$String1=0
$String2=0
$Second=$String1&$String2
#endregion decalres
#region area calculate
$Width=@DesktopWidth
$GUILeft=$Width-500
#endregion area calculate
Opt("GUIOnEventMode",1)
Opt("GUICloseOnEsc",0)
HotKeySet("{F11}","Start")
AdlibEnable("Check",150)
$mainfrm=GUICreate("Timed Bomb",500,200,$GUILeft,0,$WS_POPUPWINDOW)
$MinLabel=GUICtrlCreateLabel($Minute,-1,-1,100,200,$SS_CENTER)
$QuoteLabel=GUICtrlCreateLabel(":",100,-1,100,200,$SS_CENTER)
$seclabel=GUICtrlCreateLabel($Second,200,0,200,200,$SS_CENTER)
GUICtrlSetFont($QuoteLabel,150,800)
GUICtrlSetFont($MinLabel,150,800)
GUICtrlSetFont($seclabel,150,800)
GUISetBkColor(0xFFFFFF)
GUICtrlSetOnEvent($GUI_EVENT_CLOSE,"Quit")
WinSetOnTop($mainfrm,"",1)
GUISetState()
While 1
    Sleep(1000)
WEnd
Func Start()
    $Second=60
    For $i=0 to 49
        $String2=$String2-1
        Sleep(1000)
        GUICtrlSetData($Minlabel,$Minute)
        GUICtrlSetData($seclabel,$Second)
    Next
EndFunc
Func Quit()
    Exit
EndFunc
Func Check()
    If $String2=0 And $String1>0 Then
        $String1=$String1-1
    EndIf
    If $String1=0 And $String2=0 And $Minute>0 Then
        $Minute=$Minute-1
    EndIf
    If $String1=0 And $String2=0 And $Minute=0 Then
        Sleep(100)
    EndIf
EndFunc
Edited by Generator
Link to comment
Share on other sites

Your code was too freaking annoying to run (too hard to exit, too hard to look at, got in the way...). Had to strip all the garbage to get it down to the functional parts and then coded a working timer into it, and proper StringFormat() to show the time. If you must be annoying, you can put the other "features" back in:

#include<GUIConstants.au3>
#include<Misc.au3>

Global $RunFlag = 0
Global $TimeRemaining = 1 * 60 * 1000 ; 1 minute, in msec
Global $TimeTicks, $Minutes, $Seconds

HotKeySet("{F11}", "_Start")

Opt("GuiOnEventMode", 1)
$mainfrm = GUICreate("Timed Bomb", 500, 200, @DesktopWidth - 550, 50)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
GUISetBkColor(0xFFFFFF)

$TimeLabel = GUICtrlCreateLabel("", 10, 10, 480, 180, $SS_CENTER)
GUICtrlSetFont(-1, 125, 800)
_Check()
GUISetState()

While 1
    _Check()
    Sleep(100)
WEnd

Func _Start()
    $RunFlag = 1
    $TimeTicks = TimerInit()
EndFunc   ;==>_Start

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Func _Check()
    ; If running, decrement time remaining
    If $RunFlag Then
        $TimeRemaining -= TimerDiff($TimeTicks)
        $TimeTicks = TimerInit()
    EndIf

    ; Convert time remaining to minutes and seconds
    Local $MinCalc = Int($TimeRemaining / (60 * 1000))
    Local $SecCalc = $TimeRemaining - ($MinCalc * 60 * 1000)
    $SecCalc = Int($SecCalc / 1000)
    
    ; Detect zero
    If $MinCalc <= 0 And $SecCalc <= 0 Then
        GUISetBkColor(0xFF0000, $mainfrm)
        GUICtrlSetData($TimeLabel, "Boom!")
    Else
        ; Only update GUI when it changes
        If $MinCalc <> $Minutes Or $SecCalc <> $Seconds Then
            $Minutes = $MinCalc
            $Seconds = $SecCalc
            GUICtrlSetData($TimeLabel, StringFormat("%02u" & ":" & "%02u", $Minutes, $Seconds))
        EndIf
    EndIf
EndFunc   ;==>_Check

P.S. The Department of Homeland Security has been notified that you wanted this. Your location has been passed to field agents of the nearest CTU, and they are on their way to interrogate interview you...

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...