niksigouin Posted March 11, 2015 Share Posted March 11, 2015 I've been trying to wrap my brain around how I could set the timer the the time I want with buttons. Can anyone help me? Thanks in advance! expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $_CompteArebour = 100000, $_Minutes, $_Seconds $TimeTicks = TimerInit() $teamOneScore = 0 $teamTwoScore = 0 #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("ImproTimer", 946, 535, -1, -1) $MenuItem1 = GUICtrlCreateMenu("?") $AboutMenuItem = GUICtrlCreateMenu("About" & @TAB & "Ctrl+A") $GroupTeam1 = GUICtrlCreateGroup("", 80, 32, 257, 225) $GraphicTeam1 = GUICtrlCreateGraphic(88, 48, 240, 200) $Team1Score = GUICtrlCreateLabel($teamOneScore, 160, 56, 98, 146, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont($teamOneScore, 120, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) $ComboTeam1 = GUICtrlCreateCombo("Couleur", 8, 40, 65, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "Blanc|Bleu|Rouge|Orange|Jaune|Vert") $GroupTeam2 = GUICtrlCreateGroup("", 608, 32, 257, 225) $GraphicTeam2 = GUICtrlCreateGraphic(616, 48, 240, 200) $Team2Score = GUICtrlCreateLabel($teamTwoScore, 664, 56, 152, 146, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont($teamTwoScore, 120, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) $ComboTeam2 = GUICtrlCreateCombo("Couleur", 872, 40, 65, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "Blanc|Bleu|Rouge|Orange|Jaune|Vert") $TimerLabel = GUICtrlCreateLabel("", 352, 40, 247, 125, BitOR($SS_CENTER, $SS_CENTERIMAGE)) ;~ $Graphic1 = GUICtrlCreateGraphic( 352, 72, 247, 115) ;~ GUICtrlSetBkColor($Graphic1, 0x0033CC) GUICtrlSetData($TimerLabel, StringFormat("%02u" & ":" & "%02u", $_Minutes, $_Seconds)) GUICtrlSetFont($TimerLabel, 72, 400, 0, "MS Sans Serif") $BtnStart = GUICtrlCreateButton("Start", 352, 168, 121, 33) $BtnPause = GUICtrlCreateButton("Pause", 352, 168, 121, 33) GUICtrlSetState(-1, $GUI_HIDE) $BtnReset = GUICtrlCreateButton("Reset", 480, 168, 121, 33) $BtnAdd60 = GUICtrlCreateButton("+1 Min", 352, 208, 57, 33) $BtnAdd30 = GUICtrlCreateButton("+30 Sec", 416, 208, 57, 33) $BtnAdd10 = GUICtrlCreateButton("+10 Sec", 480, 208, 57, 33) $BtnAdd5 = GUICtrlCreateButton("+5 Sec", 544, 208, 57, 33) $PPT1 = GUICtrlCreateButton("+ 1", 8, 104, 65, 33) $MPT1 = GUICtrlCreateButton("- 1", 8, 160, 65, 33) $PPT2 = GUICtrlCreateButton("+ 1", 872, 104, 65, 33) $MPT2 = GUICtrlCreateButton("- 1", 872, 160, 65, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $BtnStart GUICtrlSetState($BtnStart, $GUI_HIDE) GUICtrlSetState($BtnPause, $GUI_SHOW) _Run() Case $ComboTeam1 $sComboRead = "" $sComboRead = GUICtrlRead($ComboTeam1) If $sComboRead = "Blanc" Then GUICtrlSetBkColor($GraphicTeam1, 0xFFFFFF) ElseIf $sComboRead = "Bleu" Then GUICtrlSetBkColor($GraphicTeam1, 0x0033CC) ElseIf $sComboRead = "Rouge" Then GUICtrlSetBkColor($GraphicTeam1, 0xFF3030) ElseIf $sComboRead = "Orange" Then GUICtrlSetBkColor($GraphicTeam1, 0xFF6600) ElseIf $sComboRead = "Jaune" Then GUICtrlSetBkColor($GraphicTeam1, 0xFFFF33) ElseIf $sComboRead = "Vert" Then GUICtrlSetBkColor($GraphicTeam1, 0x009933) EndIf Case $ComboTeam2 $sComboRead = "" $sComboRead = GUICtrlRead($ComboTeam2) If $sComboRead = "Blanc" Then GUICtrlSetBkColor($GraphicTeam2, 0xFFFFFF) ElseIf $sComboRead = "Bleu" Then GUICtrlSetBkColor($GraphicTeam2, 0x0033CC) ElseIf $sComboRead = "Rouge" Then GUICtrlSetBkColor($GraphicTeam2, 0xFF3030) ElseIf $sComboRead = "Orange" Then GUICtrlSetBkColor($GraphicTeam2, 0xFF6600) ElseIf $sComboRead = "Jaune" Then GUICtrlSetBkColor($GraphicTeam2, 0xFFFF33) ElseIf $sComboRead = "Vert" Then GUICtrlSetBkColor($GraphicTeam2, 0x009933) EndIf Case $BtnAdd60 $_CompteArebour = $_CompteArebour + 100000 Case $BtnAdd30 $_CompteArebour = $_CompteArebour + 30000 Case $BtnAdd10 $_CompteArebour = $_CompteArebour + 10000 Case $BtnAdd5 $_CompteArebour = $_CompteArebour + 5000 Case $BtnReset ;~ $_CompteArebour = 0 Case $AboutMenuItem Case $PPT1 $teamOneScore = $teamOneScore + 1 $Team1Score = GUICtrlCreateLabel($teamOneScore, 160, 56, 98, 146, BitOR($SS_CENTER, $SS_CENTERIMAGE)) Case $MPT1 $teamOneScore = $teamOneScore - 1 $Team1Score = GUICtrlCreateLabel($teamOneScore, 160, 56, 98, 146, BitOR($SS_CENTER, $SS_CENTERIMAGE)) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _Run() While 1 _Check() WEnd EndFunc ;==>_Run Func _Check() $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $BtnStart GUICtrlSetState($BtnStart, $GUI_HIDE) GUICtrlSetState($BtnPause, $GUI_SHOW) _Run() Case $BtnPause GUICtrlSetState($BtnPause, $GUI_HIDE) GUICtrlSetState($BtnStart, $GUI_SHOW) Case $BtnReset ;~ $_CompteArebour = 0 Case $BtnAdd60 $_CompteArebour = $_CompteArebour + 60000 Case $BtnAdd30 $_CompteArebour = $_CompteArebour + 30000 Case $BtnAdd10 $_CompteArebour = $_CompteArebour + 10000 Case $BtnAdd5 $_CompteArebour = $_CompteArebour + 5000 EndSwitch Local $_MinCalc = Int($_CompteArebour / (60 * 1000)), $_SecCalc = $_CompteArebour - ($_MinCalc * 60 * 1000) $_SecCalc = Int($_SecCalc / 1000) $_CompteArebour -= TimerDiff($TimeTicks) $TimeTicks = TimerInit() Local $_MinCalc = Int($_CompteArebour / (60 * 1000)), $_SecCalc = $_CompteArebour - ($_MinCalc * 60 * 1000) $_SecCalc = Int($_SecCalc / 1000) If $_MinCalc <= 0 And $_SecCalc <= 0 Then GUISetBkColor(0xFF0000, $Form1) GUICtrlSetData($TimerLabel, "Fini!") Sleep(1000) GUICtrlSetData($TimerLabel, StringFormat("%02u" & ":" & "%02u", $_Minutes, $_Seconds)) ; If @Compiled Then Shutdown ( 13 ) Else If $_MinCalc <> $_Minutes Or $_SecCalc <> $_Seconds Then $_Minutes = $_MinCalc $_Seconds = $_SecCalc GUICtrlSetData($TimerLabel, StringFormat("%02u" & ":" & "%02u", $_Minutes, $_Seconds)) If $_Minutes = 0 And $_Seconds <= 10 Then Beep(1200, 100) GUISetBkColor(0xA093FF, $Form1) EndIf EndIf EndIf EndFunc ;==>_Check Link to comment Share on other sites More sharing options...
JohnOne Posted March 11, 2015 Share Posted March 11, 2015 That's a lot of code with not much information. care to condense it to a reproducer? AutoIt Absolute BeginnersĀ Ā Require a serialĀ Ā Pause ScriptĀ Ā Video Tutorials by MorthawtĀ Ā ipifyĀ Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
niksigouin Posted March 11, 2015 Author Share Posted March 11, 2015 That's a lot of code with not much information. care to condense it to a reproducer? Will do, sorry about that!Ā Link to comment Share on other sites More sharing options...
niksigouin Posted March 11, 2015 Author Share Posted March 11, 2015 Here you go, hope it's a little better expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $_CompteArebour = 100000, $_Minutes, $_Seconds $TimeTicks = TimerInit() $Form1 = GUICreate("ImproTimer", 946, 535, -1, -1) $TimerLabel = GUICtrlCreateLabel("", 352, 40, 247, 125, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetData($TimerLabel, StringFormat("%02u" & ":" & "%02u", $_Minutes, $_Seconds)) GUICtrlSetFont($TimerLabel, 72, 400, 0, "MS Sans Serif") $BtnStart = GUICtrlCreateButton("Start", 352, 168, 121, 33) $BtnPause = GUICtrlCreateButton("Pause", 352, 168, 121, 33) GUICtrlSetState(-1, $GUI_HIDE) $BtnReset = GUICtrlCreateButton("Reset", 480, 168, 121, 33) $BtnAdd60 = GUICtrlCreateButton("+1 Min", 352, 208, 57, 33) $BtnAdd30 = GUICtrlCreateButton("+30 Sec", 416, 208, 57, 33) $BtnAdd10 = GUICtrlCreateButton("+10 Sec", 480, 208, 57, 33) $BtnAdd5 = GUICtrlCreateButton("+5 Sec", 544, 208, 57, 33) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $BtnStart ;<=== When pressed "Start", hide and then show "Pause" GUICtrlSetState($BtnStart, $GUI_HIDE) GUICtrlSetState($BtnPause, $GUI_SHOW) _Run() Case $BtnAdd60 ;=== Add 1 minute to the Timer $_CompteArebour = $_CompteArebour + 100000 Case $BtnAdd30 ;=== Add 30 seconds to the Timer $_CompteArebour = $_CompteArebour + 30000 Case $BtnAdd10 ;=== Add 10 seconds to the Timer $_CompteArebour = $_CompteArebour + 10000 Case $BtnAdd5 ;=== Add 5 seconds to the Timer $_CompteArebour = $_CompteArebour + 5000 Case $BtnReset ;=== Reset the Timer to 00:00 $_CompteArebour = 0 GUICtrlSetData($TimerLabel, StringFormat("%02u" & ":" & "%02u", $_Minutes, $_Seconds)) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _Run() While 1 _Check() WEnd EndFunc ;==>_Run Func _Check() ;==> A function I took from an other example hoping to get an input to work $nMsg = GUIGetMsg() Switch $nMsg Case $BtnStart ;<=== When pressed "Start", hide and then show "Pause" GUICtrlSetState($BtnStart, $GUI_HIDE) GUICtrlSetState($BtnPause, $GUI_SHOW) _Run() Case $BtnPause ;<=== When pressed "Pause" hide and then show "Start" GUICtrlSetState($BtnPause, $GUI_HIDE) GUICtrlSetState($BtnStart, $GUI_SHOW) Case $BtnAdd60 ;=== Add 1 minute to the Timer $_CompteArebour = $_CompteArebour + 100000 Case $BtnAdd30 ;=== Add 30 seconds to the Timer $_CompteArebour = $_CompteArebour + 30000 Case $BtnAdd10 ;=== Add 10 seconds to the Timer $_CompteArebour = $_CompteArebour + 10000 Case $BtnAdd5 ;=== Add 5 seconds to the Timer $_CompteArebour = $_CompteArebour + 5000 Case $BtnReset ;=== Reset the Timer to 00:00 $_CompteArebour = 0 GUICtrlSetData($TimerLabel, StringFormat("%02u" & ":" & "%02u", $_Minutes, $_Seconds)) Case $GUI_EVENT_CLOSE Exit EndSwitch Local $_MinCalc = Int($_CompteArebour / (60 * 1000)), $_SecCalc = $_CompteArebour - ($_MinCalc * 60 * 1000) $_SecCalc = Int($_SecCalc / 1000) $_CompteArebour -= TimerDiff($TimeTicks) $TimeTicks = TimerInit() Local $_MinCalc = Int($_CompteArebour / (60 * 1000)), $_SecCalc = $_CompteArebour - ($_MinCalc * 60 * 1000) $_SecCalc = Int($_SecCalc / 1000) If $_MinCalc <= 0 And $_SecCalc <= 0 Then GUISetBkColor(0xFF0000, $Form1) GUICtrlSetData($TimerLabel, "Fini!") Sleep(1000) GUICtrlSetData($TimerLabel, StringFormat("%02u" & ":" & "%02u", $_Minutes, $_Seconds)) ; If @Compiled Then Shutdown ( 13 ) Else If $_MinCalc <> $_Minutes Or $_SecCalc <> $_Seconds Then $_Minutes = $_MinCalc $_Seconds = $_SecCalc GUICtrlSetData($TimerLabel, StringFormat("%02u" & ":" & "%02u", $_Minutes, $_Seconds)) If $_Minutes = 0 And $_Seconds <= 10 Then Beep(1200, 100) GUISetBkColor(0xA093FF, $Form1) EndIf EndIf EndIf EndFunc ;==>_Check I'm trying to have a working timer that I can input the time I desire with that said, a Start, Pause and Reset is obliged. Link to comment Share on other sites More sharing options...
JohnOne Posted March 11, 2015 Share Posted March 11, 2015 (edited) Seems to be working, what's the problem? EDIT: For some pause functions, try the link in my signature. Forget the first one, and go for the GUI button one. Edited March 11, 2015 by JohnOne AutoIt Absolute BeginnersĀ Ā Require a serialĀ Ā Pause ScriptĀ Ā Video Tutorials by MorthawtĀ Ā ipifyĀ Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted March 11, 2015 Share Posted March 11, 2015 To fix you add 1 minute. Change the appropriate lines to this. Case $BtnAdd60 ;=== Add 1 minute to the Timer $_CompteArebour = $_CompteArebour + (1000 * 60) AutoIt Absolute BeginnersĀ Ā Require a serialĀ Ā Pause ScriptĀ Ā Video Tutorials by MorthawtĀ Ā ipifyĀ Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
niksigouin Posted March 11, 2015 Author Share Posted March 11, 2015 Seems to be working, what's the problem? EDIT:Ā For some pause functions, try the link in my signature. Forget the first one, and go for the GUI button one. I'd like the time to be posted before I have to press Start & What do you mean by GUI button one? Link to comment Share on other sites More sharing options...
JohnOne Posted March 11, 2015 Share Posted March 11, 2015 And to fix the reset button change the lines... $_CompteArebour = 0 To $_CompteArebour = 100000 AutoIt Absolute BeginnersĀ Ā Require a serialĀ Ā Pause ScriptĀ Ā Video Tutorials by MorthawtĀ Ā ipifyĀ Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted March 11, 2015 Share Posted March 11, 2015 What do you mean by GUI button one? Ā There is a link below my posts that say Pause Script. Click it and you'll find a pause function to suit you. AutoIt Absolute BeginnersĀ Ā Require a serialĀ Ā Pause ScriptĀ Ā Video Tutorials by MorthawtĀ Ā ipifyĀ Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted March 11, 2015 Share Posted March 11, 2015 I'd like the time to be posted before I have to press Start $_Minutes = 1, $_Seconds = 39 AutoIt Absolute BeginnersĀ Ā Require a serialĀ Ā Pause ScriptĀ Ā Video Tutorials by MorthawtĀ Ā ipifyĀ Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
niksigouin Posted March 11, 2015 Author Share Posted March 11, 2015 Ā And to fix the reset button change the lines... $_CompteArebour = 0 To $_CompteArebour = 100000 Thanks for helping by the way! & the reason why the value is set to 0 when reset is pressed is because I want it to reset to 0 and not then initially declared value Link to comment Share on other sites More sharing options...
JohnOne Posted March 11, 2015 Share Posted March 11, 2015 GUICtrlSetData($TimerLabel, StringFormat("%02u" & ":" & "%02u", 0, 0)) AutoIt Absolute BeginnersĀ Ā Require a serialĀ Ā Pause ScriptĀ Ā Video Tutorials by MorthawtĀ Ā ipifyĀ Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
niksigouin Posted March 11, 2015 Author Share Posted March 11, 2015 GUICtrlSetData($TimerLabel, StringFormat("%02u" & ":" & "%02u", 0, 0)) This works wonderfully for the Reset, thanks! Link to comment Share on other sites More sharing options...
JohnOne Posted March 11, 2015 Share Posted March 11, 2015 If you have more problem, try to describe them in more detail. What is wrong What you need What you tried etc... AutoIt Absolute BeginnersĀ Ā Require a serialĀ Ā Pause ScriptĀ Ā Video Tutorials by MorthawtĀ Ā ipifyĀ Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
niksigouin Posted March 11, 2015 Author Share Posted March 11, 2015 (edited) $_Minutes = 1, $_Seconds = 39 Not quite like that, I want the input from theĀ $BtnAdd60 to show up in my label as I pressed it. Like a Microwave timer. EDIT: I tried Global $minVal = 0 Global $secVal = 0 Global $_CompteArebour = 0, $_Minutes = $minVal, $_Seconds = $secVal AND Case $BtnAdd60 ;=== Add 1 minute to the Timer $minVal = $minVal + (1000 * 60) GUICtrlSetData($TimerLabel, StringFormat("%02u" & ":" & "%02u", $_Minutes, $_Seconds)) Hopping it would refresh the label to the new value Edited March 11, 2015 by niksigouin Link to comment Share on other sites More sharing options...
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