Rapid Posted October 18, 2015 Share Posted October 18, 2015 (edited) $Form1 = GUICreate("D2", 128, 77, 292, 327) $Timer = GUICtrlCreateInput("0", 2, 3, 25, 21) Func Timer($val) Dim $i_TimeStamp = TimerInit() Dim $i_TimeToCountDownFromSeconds = $val Dim $i_OriginalSeconds = $i_TimeToCountDownFromSeconds While $i_TimeToCountDownFromSeconds > 0 If TimerDiff($i_TimeStamp) >= 100 Then $i_TimeStamp = TimerInit() IF $i_TimeToCountDownFromSeconds = 0 Then Exitloop $i_TimeToCountDownFromSeconds -= 0.1 GUICtrlSetData($Timer, $i_TimeToCountDownFromSeconds) IF GUICtrlRead($Timer) < 0 then GUICtrlSetData($Timer,"0") EndIf EndIf sleep(10) WEnd EndFunc [/code] For some reason when I use this, and for example if I set the timer val to be 3 (3 seconds) with jumps of 0.1 miliseconduntill 1 its all fine, but when it goes below 1 to 0.9 it shows a random number (example: 90349030) untill it reaches 0I dont not want to miss the 0.9 to 0 process.Any code fix you guys could suggest?$val stands for the time to count down from And another question - How can I make 2 timers run at the same time? I cant get it to work :(. When I start 1 timer and then the 2nd timer it will just pause the first one and start the second one Edited October 18, 2015 by Rapid Link to comment Share on other sites More sharing options...
JohnOne Posted October 19, 2015 Share Posted October 19, 2015 First, Your code does not do anything.Second, Timers don't "Run" they are just time stamps, you can have as many as you like. 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...
kylomas Posted October 20, 2015 Share Posted October 20, 2015 Try this...GUICtrlSetData($Timer, stringformat('%2.1f',$i_TimeToCountDownFromSeconds)) Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Rapid Posted October 20, 2015 Author Share Posted October 20, 2015 JohnOne ofocurse it doesnt run.. I only copied a few lines q_q.And I still have problem... they wont run at the same time !!! If I turn one of them on the 2nd one will stop.... what can I do in order to make them all run at the same time if I want to... if I have 1 timer runnign from 10 to 0 and its on 5 at the moment and I start the second timer then it will run 10 to 0 on the second timer and only then keep going with the first one... why is that?? any help :(? Link to comment Share on other sites More sharing options...
JohnOne Posted October 20, 2015 Share Posted October 20, 2015 If you had a script that could actually run, you'd get way more help. 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...
Rapid Posted October 20, 2015 Author Share Posted October 20, 2015 expandcollapse popup#include <AVIConstants.au3> #include <GuiConstantsEx.au3> #include <TreeViewConstants.au3> #include <GUIConstants.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #Region ### Global Vars ### Global Const $sLogFile = 'log.txt' Global $hFileOpen = FileOpen($sLogFile, $FO_APPEND) #EndRegion ### Global Vars ### #Region ### HotKeys ### HotKeySet("{ESC}", "ExitProg") HotKeySet("^z","S1") HotKeySet("^x","S2") HotKeySet("^c","S3") HotKeySet("^v","S4") #EndRegion ### HotKeys ### #Region ### GUI ### #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("D2", 128, 77, 292, 327) $Input1 = GUICtrlCreateInput("Txt", 2, 3, 25, 21) $Input2 = GUICtrlCreateInput("Txt", 34, 3, 25, 21) $Input3 = GUICtrlCreateInput("Txt", 66, 3, 25, 21) $Input4 = GUICtrlCreateInput("Txt", 98, 3, 25, 21) $S1T = GUICtrlCreateInput("", 2, 29, 26, 21) $S2T = GUICtrlCreateInput("", 34, 29, 26, 21) $S3T = GUICtrlCreateInput("", 66, 29, 26, 21) $S4T = GUICtrlCreateInput("", 98, 29, 26, 21) $Timer1 = GUICtrlCreateInput("0", 2, 53, 26, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY)) $Timer2 = GUICtrlCreateInput("0", 34, 53, 26, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY)) $Timer3 = GUICtrlCreateInput("0", 66, 53, 26, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY)) $Timer4 = GUICtrlCreateInput("0", 98, 53, 26, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd #EndRegion ### GUI ### func S1() $time = GUICtrlRead($S1T) Timer($time,$Timer1) EndFunc func S2() $time = GUICtrlRead($S2T) Timer2($time,$Timer2) EndFunc func S3() $time = GUICtrlRead($S3T) Timer($time,$Timer3) EndFunc func S4() $time = GUICtrlRead($S4T) Timer($time,$Timer4) EndFunc Func Timer($val,$Timer) Dim $i_TimeStamp = TimerInit() Dim $i_TimeToCountDownFromSeconds = $val Dim $i_OriginalSeconds = $i_TimeToCountDownFromSeconds While $i_TimeToCountDownFromSeconds > 0 If TimerDiff($i_TimeStamp) >= 100 Then $i_TimeStamp = TimerInit() IF $i_TimeToCountDownFromSeconds = 0 Then Exitloop $i_TimeToCountDownFromSeconds -= 0.1 GUICtrlSetData($Timer1, stringformat('%2.1f',$i_TimeToCountDownFromSeconds)) IF GUICtrlRead($Timer) < 0 then GUICtrlSetData($Timer,"0") EndIf EndIf sleep(10) WEnd EndFunc Func Timer2($val,$Timer) Dim $i_TimeStamp = TimerInit() Dim $i_TimeToCountDownFromSeconds = $val Dim $i_OriginalSeconds = $i_TimeToCountDownFromSeconds While $i_TimeToCountDownFromSeconds > 0 If TimerDiff($i_TimeStamp) >= 100 Then $i_TimeStamp = TimerInit() IF $i_TimeToCountDownFromSeconds = 0 Then Exitloop $i_TimeToCountDownFromSeconds -= 0.1 GUICtrlSetData($Timer2, stringformat('%2.1f',$i_TimeToCountDownFromSeconds)) IF GUICtrlRead($Timer2) < 0 then GUICtrlSetData($Timer2,"0") EndIf EndIf sleep(10) WEnd EndFunc while(1) ;always active sleep(100) WEnd Func ExitProg() Exit EndFunc ;==>ExitProg just set values in the second line (numbers)and hit ctrl+z and ctrl+x ... you will see what happen and maybe help me solve it Link to comment Share on other sites More sharing options...
kylomas Posted October 20, 2015 Share Posted October 20, 2015 (edited) $i_TimeStamp is the only timer you are using. Therfore your 2ND call just resets the timer to whatever is current when you call it. You need different variables for different timers. Arrays are really handy for this.kylomas Edited October 20, 2015 by kylomas spelling Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
JohnOne Posted October 20, 2015 Share Posted October 20, 2015 (edited) Stripped your code down to show basic example of showing two counters.Just try to get what and why, then you can adapt principal to your goal.expandcollapse popup#include <AVIConstants.au3> #include <GuiConstantsEx.au3> #include <TreeViewConstants.au3> #include <GUIConstants.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #Region ### Global Vars ### Global Const $sLogFile = 'log.txt' Global $bTimer1Started = False, $bTimer2Started = False, $time1, $time2, $FuncStarted = False Global $hFileOpen = FileOpen($sLogFile, $FO_APPEND) #EndRegion ### Global Vars ### #Region ### HotKeys ### HotKeySet("{ESC}", "ExitProg") HotKeySet("^1", "S1") HotKeySet("^2", "S2") #EndRegion ### HotKeys ### #Region ### GUI ### #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("D2", 228, 177, 292, 327) $Input1 = GUICtrlCreateInput("Txt", 2, 3, 100, 21) $Input2 = GUICtrlCreateInput("Txt", 120, 3, 100, 21) $Abort = GUICtrlCreateButton("Abort", 10, 100) $S1T = GUICtrlCreateInput("", 2, 29, 100, 21) $S2T = GUICtrlCreateInput("", 120, 29, 100, 21) $hTimer1 = GUICtrlCreateInput("0", 2, 53, 100, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY)) $hTimer2 = GUICtrlCreateInput("0", 120, 53, 100, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd #EndRegion ### GUI ### Func S1() If $bTimer1Started Then Return $time1 = TimerInit() $bTimer1Started = True If $FuncStarted Then Return Timer() EndFunc ;==>S1 Func S2() If $bTimer2Started Then Return $bTimer2Started = True $time2 = TimerInit() If $FuncStarted Then Return Timer() EndFunc ;==>S2 Func Timer() $FuncStarted = True While 1 If $bTimer1Started Then GUICtrlSetData($hTimer1, Round(TimerDiff($time1), 2)) EndIf If $bTimer2Started Then GUICtrlSetData($hTimer2, Round(TimerDiff($time2), 2)) EndIf Sleep(500) If GUIGetMsg() = -3 Then Exit If GUIGetMsg() = $Abort Then ExitLoop WEnd $FuncStarted = False $bTimer1Started = False GUICtrlSetData($hTimer1, "") $bTimer2Started = False GUICtrlSetData($hTimer2, "") EndFunc ;==>Timer Func ExitProg() Exit EndFunc ;==>ExitProg Edited October 20, 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...
Rapid Posted October 21, 2015 Author Share Posted October 21, 2015 thanks but I cant manage to make it count down... :\ and in 2.1f format Link to comment Share on other sites More sharing options...
JohnOne Posted October 21, 2015 Share Posted October 21, 2015 You already made the code to count down. 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...
Rapid Posted October 22, 2015 Author Share Posted October 22, 2015 And I tried doing it the same way you did and it didn't work :(.Ill post the code when I wake up its on my laptop and see maybe u can understand why, thanks ! 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