Jump to content

Start/Reset Timer Macro /w GUI


Recommended Posts

Hey Guys,

I'm wondering if I can have a little bit of help creating a start/reset macro

Below I have a default GUI for the purposes of the macro to help better illustrate it, please note there will be more than one of these in the final version so about 10 reset buttons and 10 start buttons with 10 status's

When "Start" is clicked $StatusDynamicLabel should be changed from "Ready" to a red countdown from 60minutes (inlcuding seconds) down to 0, when it hits zero it should change to a green "Ready"

If Reset is clicked during or after the countdown has finished then it should start counting down again from 60.

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

Opt("GUIOnEventMode", 1)

Local $GUIWidth = 280, $GUIHeight = 75
Dim $GUIPosX = (@DesktopWidth - $GUIWidth) / 2
Dim $GUIPosY = (@DesktopHeight - $GUIHeight) / 2

$HoTimer = GUICreate("HoTimer", $GUIWidth, $GUIHeight, $GUIPosX, $GUIPosY)
$FWTGroup = GUICtrlCreateGroup("F W T", 8, 8, 265, 50)
$StatusLabel = GUICtrlCreateLabel("Status: ", 13, 23, 60, 26)
GUICtrlSetFont(-1, 12, 800, 0, "Trebuchet MS")
$StatusDynamicLabel = GUICtrlCreateLabel("Ready", 68, 26, 45, 22)
GUICtrlSetFont(-1, 10, 400, 0, "Trebuchet MS")
$ResetButton = GUICtrlCreateButton("Reset", 118, 23, 75, 25)
$StartButton = GUICtrlCreateButton("Start", 193, 23, 75, 25)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState(@SW_SHOW)

While 1
Sleep(100)
WEnd

Func _Exit()
GUIDelete()
Exit
EndFunc   ;==>_Exit

If anyone could help me achieve this function then I would greatly appreciate it.

Link to comment
Share on other sites

I made this one:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $TIMER
Local $GUIWidth = 280, $GUIHeight = 75
Dim $GUIPosX = (@DesktopWidth - $GUIWidth) / 2
Dim $GUIPosY = (@DesktopHeight - $GUIHeight) / 2
$HoTimer = GUICreate("HoTimer", $GUIWidth, $GUIHeight, $GUIPosX, $GUIPosY)
$FWTGroup = GUICtrlCreateGroup("F W T", 8, 8, 265, 50)
$StatusLabel = GUICtrlCreateLabel("Status: ", 13, 23, 60, 26)
GUICtrlSetFont(-1, 12, 800, 0, "Trebuchet MS")
$StatusDynamicLabel = GUICtrlCreateLabel("Ready", 68, 26, 45, 22)
GUICtrlSetFont(-1, 10, 400, 0, "Trebuchet MS")
$ResetButton = GUICtrlCreateButton("Stop", 118, 23, 75, 25)
GuiCtrlSetState($ResetButton, $GUI_DISABLE)
$StartButton = GUICtrlCreateButton("Start/Reset", 193, 23, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $StartButton
$TIMER = TimerInit()
GuiCtrlSetState($ResetButton, $GUI_ENABLE)
GuiCtrlSetState($StartButton, $GUI_DISABLE)
Case $ResetButton
$TIME = TimerDiff($TIMER)
msgbox(64, "", "Timer stopped after " & $TIME/1000 & " seconds")
$TIME = 0
GuiCtrlSetState($ResetButton, $GUI_DISABLE)
GuiCtrlSetState($StartButton, $GUI_ENABLE)
EndSwitch
WEnd

Was this helpful?

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to comment
Share on other sites

Hey, I just started editing the macro and I've just edited this post to show one part I've fixed but now I have the issue turning miliseconds into seconds then turning that into a countdown time.

I have one problem which i've commented in, please could someone take a look and help me out.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $nTimer
Local $GUIWidth = 280, $GUIHeight = 75
Dim $GUIPosX = (@DesktopWidth - $GUIWidth) / 2
Dim $GUIPosY = (@DesktopHeight - $GUIHeight) / 2
$HoTimer = GUICreate("HoTimer", $GUIWidth, $GUIHeight, $GUIPosX, $GUIPosY)
$FWTGroup = GUICtrlCreateGroup("F W T", 8, 8, 265, 50)
$StatusLabel = GUICtrlCreateLabel("Status: ", 13, 23, 60, 26)
GUICtrlSetFont(-1, 12, 800, 0, "Trebuchet MS")
$StatusDynamicLabel = GUICtrlCreateLabel("Ready", 68, 26, 45, 22)
GUICtrlSetFont(-1, 10, 400, 0, "Trebuchet MS")
$ResetButton = GUICtrlCreateButton("Stop", 118, 23, 75, 25)
GUICtrlSetState($ResetButton, $GUI_DISABLE)
$StartButton = GUICtrlCreateButton("Start/Reset", 193, 23, 75, 25)
GUISetState(@SW_SHOW)

$StatusCounter = 0
$nTime = 0

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $StartButton
            $nTimer = TimerInit()
            $StatusCounter = 1
            GUICtrlSetState($ResetButton, $GUI_ENABLE)
            GUICtrlSetState($StartButton, $GUI_DISABLE)
        Case $ResetButton
            $nTime = StringSplit(TimerDiff($nTimer), ".", 1)
            $xTime = Ceiling($nTime[1] / 1000)
            $xMinTime = Int($xTime / 60)
            $xSecTime = $xTime - $xMinTime * 60
            $xTime = StringFormat('%02d:%02d', $xMinTime, $xSecTime)
            $nTime = 0
            $StatusCounter = 0
            GUICtrlSetData($StatusDynamicLabel, "N/A")
            GUICtrlSetState($ResetButton, $GUI_DISABLE)
            GUICtrlSetState($StartButton, $GUI_ENABLE)
    EndSwitch
    If $StatusCounter = 1 Then
        $nTime = StringSplit(TimerDiff($nTimer), ".", 1)
        $nTimeFull = Ceiling($nTime[1] / 1000)
        $nCountdown = 3600 - $nTimeFull
        $xMinTime = Int($nCountdown / 60)
        $xSecTime = $nCountdown - $xMinTime * 60
        $nCountdown = StringFormat('%02d:%02d', $xMinTime, $xSecTime)
        GUICtrlSetData($StatusDynamicLabel, "" & $nCountdown)
        ; This part isn't working, it should Stop counting down after 10 seconds...
        If $nTimeFull = 3590 Then
            GUICtrlSetData($StatusDynamicLabel, "Ready")
            $StatusCounter = 0
        EndIf
    EndIf
WEnd
Edited by XxXGoD
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...