Jump to content
Sign in to follow this  
Kirkis669

Time countdown (in minutes)

Recommended Posts

Hi all,

I am trying to create a simple countdown function that would take amount of minutes from InputBox and show "live" remaining time in minutes. My script stops after the first minute of deduction. 

Could you help?

Script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form4 = GUICreate("Spot Request Form", 291, 329, 491, 230)

$Finale = GUICtrlCreateButton("Summarize", 150, 264, 130, 50)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")


$Limit = GUICtrlCreateInput("(min)", 150, 40, 110, 33)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")

$SpotLimit = GUICtrlCreateLabel("SpotLimit", 150, 8, 85, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")


$Label3 = GUICtrlCreateLabel("Time left", 150, 152, 78, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Time = GUICtrlCreateLabel("00", 160, 184, 100, 72)
GUICtrlSetFont(-1, 48, 800, 0, "OCR A Std")
GUICtrlSetColor(-1, 0xFF0000)

GUISetState(@SW_SHOW)


      

While 1
    $nMsg = GUIGetMsg()


   $Minutes = GUICtrlRead ($Limit)


      Switch $nMsg
   Case $GUI_EVENT_CLOSE
      Exit


   Case $Finale

   GUICtrlSetData($Time, $Minutes)
   Sleep (1000)
   $Minutes = $Minutes - 1
      If $Minuty = -1 Then
   MsgBox (0, "Done", "Countdown finished")
   Exit
      EndIf
   Sleep (59000)           ;time needed to count a minute
   GUICtrlSetData ($Time, $Minutes)

EndSwitch
WEnd

 

 

 

Share this post


Link to post
Share on other sites

This is because your Sleep statement only sleeps for a second. Please re-read the help file for Sleep ;)

Just noticed the second Sleep statement :>

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-09-05 - Version 1.5.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

I made a workaround by declaring the desired amount of minutes in an inputbox before I run the entire GUI masive, it is not the most beautiful solution, so if you have any ideas how to create an input box and click a button to run a countdown.. I am open to any ideas :)

Share this post


Link to post
Share on other sites

Try this.... but you can finished it off. 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form4 = GUICreate("Spot Request Form", 291, 329, 491, 230)
$Finale = GUICtrlCreateButton("Summarize", 150, 264, 130, 50)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Limit = GUICtrlCreateInput("(min)", 150, 40, 110, 33)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$SpotLimit = GUICtrlCreateLabel("SpotLimit", 150, 8, 85, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Time left", 150, 152, 78, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Time = GUICtrlCreateLabel("00", 160, 184, 200, 72)
GUICtrlSetLimit(-1, 3)
GUICtrlSetFont(-1, 30, 800, 0, "OCR A Std")
GUICtrlSetColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    $Minutes = GUICtrlRead($Limit)
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Finale
            $ReadLimit = GUICtrlRead($Limit)
            If $ReadLimit = "(min)" Then
                MsgBox(-1, "No time specified", "You did not specify a time." & @CRLF & "Please insert a time in minutes.")
            Else

                GUICtrlSetData($Time, $Minutes)
                $ReadLimit = GUICtrlRead($Limit) * 60
                Local $ReadTime = GUICtrlRead($Time)
                For $i = 1 To $ReadLimit
                    GUICtrlSetData($Time, ($ReadLimit - $i) / 60 * 60)
                    Sleep(1000)
                Next

                If $ReadTime = 0 Then
                    MsgBox(0, "Done", "Countdown finished", 3)
                EndIf
                Sleep(500)
                GUICtrlSetData($Time, "00")
            EndIf
    EndSwitch
WEnd

 

Edited by Skeletor

Kind Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen

Share this post


Link to post
Share on other sites

Um how about we don't lock up the GUI while the timer is active?

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>;;

$Form4 = GUICreate("Spot Request Form", 291, 329, 491, 230)
$Finale = GUICtrlCreateButton("Summarize", 150, 264, 130, 50)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Limit = GUICtrlCreateInput("(min)", 150, 40, 110, 33)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$SpotLimit = GUICtrlCreateLabel("SpotLimit", 150, 8, 85, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Time left", 150, 152, 78, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Time = GUICtrlCreateLabel("00", 160, 184, 200, 72)
GUICtrlSetLimit(-1, 3)
GUICtrlSetFont(-1, 30, 800, 0, "OCR A Std")
GUICtrlSetColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)

Local $g_sDateStart
local $g_iTimeSeconds = 0
local $g_iTimeLast

While 1
    $nMsg = GUIGetMsg()
    $Minutes = GUICtrlRead($Limit)
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Finale
            if $g_iTimeSeconds = 0 Then
                Local $iReadLimit = GUICtrlRead($Limit)
                If $iReadLimit = "(min)" Then
                    MsgBox(-1, "No time specified", "You did not specify a time." & @CRLF & "Please insert a time in minutes.")
                Else
                    $g_sDateStart = _NowCalc()
                    $g_iTimeSeconds = $iReadLimit * 60
                    $g_iTimeLast = $g_iTimeSeconds
                    GUICtrlSetData($Time, Int($g_iTimeSeconds / 60) & "." & Mod($g_iTimeSeconds, 60) )
                    consolewrite("Seconds: " & $g_iTimeSeconds & @CRLF)
                EndIf
            EndIf
        Case 0 ;Event None
            if $g_iTimeSeconds > 0 Then
                Local $iTime = $g_iTimeSeconds - _DateDiff('s', $g_sDateStart, _NowCalc())
                if $iTime < $g_iTimeLast Then
                    $g_iTimeLast = $iTime ;update the last count

                    If $iTime <= 0 Then ; <= in case we miss the event
                        GUICtrlSetData($Time, "00")
                        $g_iTimeSeconds = 0
                        MsgBox(0, "Done", "Countdown finished", 3)                  
                    Else
                        GUICtrlSetData($Time, Int($iTime / 60) & "." & Mod($iTime, 60) )
                    EndIf
                Endif
            Endif
    EndSwitch
WEnd

 

 

Edited by Bilgus

Share this post


Link to post
Share on other sites

This is probably slightly more efficient...

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPISys.au3>;;

$Form4 = GUICreate("Spot Request Form", 291, 329, 491, 230)
$Finale = GUICtrlCreateButton("Summarize", 150, 264, 130, 50)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Limit = GUICtrlCreateInput("(min)", 150, 40, 110, 33)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$SpotLimit = GUICtrlCreateLabel("SpotLimit", 150, 8, 85, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Time left", 150, 152, 78, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Time = GUICtrlCreateLabel("00", 160, 184, 200, 72)
GUICtrlSetLimit(-1, 3)
GUICtrlSetFont(-1, 30, 800, 0, "OCR A Std")
GUICtrlSetColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)

Local $g_sDateStart
local $g_iTimeSeconds = 0
local $g_iTimeLast

While 1
    $nMsg = GUIGetMsg()
    $Minutes = GUICtrlRead($Limit)
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Finale
            if $g_iTimeSeconds = 0 Then
                Local $iReadLimit = GUICtrlRead($Limit)
                If $iReadLimit = "(min)" Then
                    MsgBox(-1, "No time specified", "You did not specify a time." & @CRLF & "Please insert a time in minutes.")
                Else
                    $g_iTimeStart = _WinAPI_GetTickCount64() ;_WinAPI_GetTickCount() if you are not vista+ but then you have to worry about rollover
                    $g_iTimeSeconds = $iReadLimit * 60
                    $g_iTimeLast = $g_iTimeSeconds
                    GUICtrlSetData($Time, Int($g_iTimeSeconds / 60) & "." & Mod($g_iTimeSeconds, 60) )
                    consolewrite("Seconds: " & $g_iTimeSeconds & @CRLF)
                EndIf
            EndIf
        Case 0 ;Event None
            if $g_iTimeSeconds > 0 Then
                Local $iTime = $g_iTimeSeconds - Int((_WinAPI_GetTickCount64() - $g_iTimeStart) / 1000) ;_WinAPI_GetTickCount() if you are not vista+
                if $iTime < $g_iTimeLast Then
                    $g_iTimeLast = $iTime ;update the last count

                    If $iTime <= 0 Then ; <= in case we miss the event
                        GUICtrlSetData($Time, "00")
                        $g_iTimeSeconds = 0
                        MsgBox(0, "Done", "Countdown finished", 3)
                    Else
                        GUICtrlSetData($Time, Int($iTime / 60) & "." & Mod($iTime, 60) )
                    EndIf
                Endif
            Endif
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites

Made this some time ago, for shutdown.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Resources\Clock.ico
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Icon_Add=Resources\Clock.ico
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Opt("TrayAutoPause", 0)
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Time4Shutdown", 395, 32, 250, 475, -1, $WS_EX_DLGMODALFRAME)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
$settime = GUICtrlCreateInput("", 168, 5, 49, 21)
$Label1 = GUICtrlCreateLabel("Set time for shutdown in minutes", 8, 8, 156, 17)
$Button1 = GUICtrlCreateButton("Start", 234, 3, 75, 25)
GUICtrlSetOnEvent($Button1, "Start")
$Button2 = GUICtrlCreateButton("Reboot", 314, 3, 75, 25)
GUICtrlSetOnEvent($Button2, "Reboot")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Func Start()
    GUISetState(@SW_HIDE)
    $time = GUICtrlRead($settime, 1)
    $timetosleep = $time * 60
    Do
        ToolTip($timetosleep & ' Seconds Remanining', 300, 0)
        Sleep(995)
        $timetosleep -= 1
    Until $timetosleep <= 0
    ToolTip("")
    Shutdown(13)
    Exit
EndFunc   ;==>Start

Func Reboot()
    Local $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(4164, "Notice", "Do you really want to reboot?")
    Select
        Case $iMsgBoxAnswer = 6 ;Yes
        Case $iMsgBoxAnswer = 7 ;No
    EndSelect
    If $iMsgBoxAnswer = 6 Then
        MsgBox(4096, "Notice", "Clicked Yes! Going to reboot")
        Shutdown(6)
    ElseIf $iMsgBoxAnswer = 7 Then
        MsgBox(4096, "Notice", "Clicked No! Aborting reboot")
    EndIf
EndFunc   ;==>Reboot

Func Close()
    Exit
EndFunc   ;==>Close

Do
    Sleep(100)
Until $Form1 = $GUI_EVENT_CLOSE

 

Edited by careca

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

Edited post


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...