tomagucci Posted October 1, 2008 Share Posted October 1, 2008 (edited) So heres the deal, I have a timer that runs and exits at the beginning of my script, when it exits a bunch of specified tasks run then the code is repeated, when it starts over, I have another timer there, but for some reason the second timer does not get the defined time and stays at "00:00:00", any help would be greatly appreciated. heres the first timer code expandcollapse popup#include <GUIConstants.au3> #include <Date.au3> Dim $SleepTime = 43000 Dim $SleepTime2 = 4300 Global $timer = TimerInit() Global $timer2 = TimerInit() Global $Secs, $Mins, $Hour, $Time, $Time2, $Secs2, $Mins2, $Hour2 Func SleepTimer() <--- this one works perfectly AdlibEnable("Timer", 50) create() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GuiDelete ($sleeptimer) Return EndSelect Wend Timer() sleep ($SleepTime) EndFunc func Create() Global $sleeptimer = GUICreate("Timer for Sleep",240, 50) GUICtrlCreateLabel("00:00:00", 10,10) GUISetState() EndFunc Func Timer() _TicksToTime($SleepTime-Int(TimerDiff($timer)), $Hour, $Mins, $Secs ) Local $sTime = $Time; save current time to be able to test and avoid flicker.. $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs) If $sTime <> $Time Then ControlSetText("Timer", "", "Static1", $Time) If $sTime = "00:00:00" Then GUIDelete ($sleeptimer) EndIf EndFunc;Timer here is the second one, it just starts and stops at "00:00:00", the if then code actually closes it right away because it doesnt change from "00:00:00" Func SleepTimer2() AdlibEnable("Timer2", 50) create2() While 1 $msg2 = GUIGetMsg() Select Case $msg2 = $GUI_EVENT_CLOSE GuiDelete ($sleeptimer2) Return EndSelect Wend Timer2() sleep ($SleepTime2) EndFunc func Create2() Global $SleepTimer2 = GUICreate("Timer",240, 50) GUICtrlCreateLabel("00:00:00", 10,10) GUISetState() EndFunc Func Timer2() _TicksToTime($SleepTime2-Int(TimerDiff($timer2)), $Hour2, $Mins2, $Secs2) Local $sTime2 = $Time2; save current time to be able to test and avoid flicker.. $Time2 = StringFormat("%02i:%02i:%02i", $Hour2, $Mins2, $Secs2) If $sTime2 <> $Time2 Then ControlSetText("Timer", "", "Static1", $Time2) ;If $sTime2 = "00:00:00" Then ;GUIDelete ($SleepTimer2) ;EndIf EndFunc;==>Timerexpandcollapse popup Edited October 1, 2008 by tomagucci Link to comment Share on other sites More sharing options... Aceguy Posted October 1, 2008 Aceguy Active Members 629 YAY ME..... Share Posted October 1, 2008 Hope this helps as am example #include <GUIConstants.au3> #include <Date.au3> Global $time Dim $Label[3] dim $time[3] $time[1] =10 $time[2] =4 $Form1 = GUICreate("Form1", 475, 250, 249, 172) $Label[1] = GUICtrlCreateLabel("Label1", 16, 24, 36, 17) $Label[2] = GUICtrlCreateLabel("Label2", 24, 64, 36, 17) GUISetState(@SW_SHOW) AdlibEnable("time", 1000) While 1 Sleep(250) WEnd Func time() For $x = 1 To 2 $time[$x]+=1 GUICtrlSetData($Label[$x], $time[$x]) Next EndFunc ;==>time [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
Aceguy Posted October 1, 2008 Share Posted October 1, 2008 and with a reset add Func time() For $x = 1 To 2 $time[$x]+=1 GUICtrlSetData($Label[$x], $time[$x]) ; with a reset if $time[2] = 15 then $time[2]=0 Next EndFunc ;==>time [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
tomagucci Posted October 1, 2008 Author Share Posted October 1, 2008 (edited) but i need a gui created and closed, and then another created and closed. it has to be linearly, do you think that is why its messing up?, If i just put the second into auto it by itself without anything it works, but when it is at the end of the large function, it messes up, is there something that is carried over and not reset? is there something I can do to reset it? Edited October 1, 2008 by tomagucci Link to comment Share on other sites More sharing options...
tomagucci Posted October 1, 2008 Author Share Posted October 1, 2008 (edited) something is messing up even before the sleep($sleeptime2) because its not like the gui is just opened and closed, the script just stops there, script is still running, just nothing is happening. anyone got a clue? Edited October 1, 2008 by tomagucci Link to comment Share on other sites More sharing options...
Aceguy Posted October 1, 2008 Share Posted October 1, 2008 (edited) but i need a gui created and closed, and then another created and closedso 2 guis, each with a timer??? Edited October 1, 2008 by Aceguy [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
dbzfanatic Posted October 1, 2008 Share Posted October 1, 2008 You really should just create the GUIs outside a function/loop then show the one that needs to be called. $frmGUI1 = GUICreate("GUI 1",-1,-1,-1,-1) $frmGUI2 = GUICreate("GUI 2",-1,-1,-1,-1) GUISetState(@SW_SHOW,$frmGUI1) ;do something GUISetState(@SW_HIDE,$frmGUI1) GUISetState(@SW_SHOW,$frmGUI2) ;do stuff here Not a very elegant example but it gets the point across Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
do3z Posted October 1, 2008 Share Posted October 1, 2008 I Like The Following Code But What If I Wanted To Close The Program ?? This Is Not Alowing Me To Close? expandcollapse popup#include <GUIConstants.au3> #include <Date.au3> Dim $SleepTime = 43000 Dim $SleepTime2 = 4300 Global $timer = TimerInit() Global $timer2 = TimerInit() Global $Secs, $Mins, $Hour, $Time, $Time2, $Secs2, $Mins2, $Hour2 Func SleepTimer() <--- this one works perfectly AdlibEnable("Timer", 50) create() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GuiDelete ($sleeptimer) Return EndSelect Wend Timer() sleep ($SleepTime) EndFunc func Create() Global $sleeptimer = GUICreate("Timer for Sleep",240, 50) GUICtrlCreateLabel("00:00:00", 10,10) GUISetState() EndFunc Func Timer() _TicksToTime($SleepTime-Int(TimerDiff($timer)), $Hour, $Mins, $Secs ) Local $sTime = $Time; save current time to be able to test and avoid flicker.. $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs) If $sTime <> $Time Then ControlSetText("Timer", "", "Static1", $Time) If $sTime = "00:00:00" Then GUIDelete ($sleeptimer) EndIf EndFunc;Timer here is the second one, it just starts and stops at "00:00:00", the if then code actually closes it right away because it doesnt change from "00:00:00" Func SleepTimer2() AdlibEnable("Timer2", 50) create2() While 1 $msg2 = GUIGetMsg() Select Case $msg2 = $GUI_EVENT_CLOSE GuiDelete ($sleeptimer2) Return EndSelect Wend Timer2() sleep ($SleepTime2) EndFunc func Create2() Global $SleepTimer2 = GUICreate("Timer",240, 50) GUICtrlCreateLabel("00:00:00", 10,10) GUISetState() EndFunc Func Timer2() _TicksToTime($SleepTime2-Int(TimerDiff($timer2)), $Hour2, $Mins2, $Secs2) Local $sTime2 = $Time2; save current time to be able to test and avoid flicker.. $Time2 = StringFormat("%02i:%02i:%02i", $Hour2, $Mins2, $Secs2) If $sTime2 <> $Time2 Then ControlSetText("Timer", "", "Static1", $Time2) ;If $sTime2 = "00:00:00" Then ;GUIDelete ($SleepTimer2) ;EndIf EndFunc;==>Timer[code] Google Is For Real Men. Yahoo Is For Wimps! Link to comment Share on other sites More sharing options...
tomagucci Posted October 2, 2008 Author Share Posted October 2, 2008 i dont want to close it, i just want, if i close the gui to go onto the next function in the main script. I am just having trouble with the second timer.... blah I tried to make 2 at the same time but it doesnt work... the second one still doesnt show up... Link to comment Share on other sites More sharing options...
tomagucci Posted October 2, 2008 Author Share Posted October 2, 2008 can anyone help me out with getting the second one to function, or tell me why it doesnt work like it should? Link to comment Share on other sites More sharing options...
tomagucci Posted October 2, 2008 Author Share Posted October 2, 2008 (edited) blah, now i realize that it isn't even going to the next function in the script, it only goes to the next Function if i close it by clicking the X..... can someone explain why?, see all it is is that I need the script to sleep for a very long time (excess of 3+ more hours) I want there to be something showing the time left for sleep, the thing is though, that I dont want it shown in milliseconds, I want it in 00:00:00 and the only way i know how to get that format is through a GUI, if anyone has a better or different approach I would love to hear it, and there are multiple places where the script will sleep, I need a window to show that sleep time each time. I just thought of something that might work, but im not exactly sure how to do it, can I just recall $sleeptimer, the first one, and reset it back to 00:00:00 and have another timer() function do another countdown with a different variable. anyone got any ideas? EDIT: I just found out what the problem is, okay whether i use two different gui, or the same one, the time for the gui does not get reset back to zero then pick up the new tickstotime, if i close the gui at 43 seconds, when the second one opens it starts from 43 and not from where the variable should start from. Edited October 2, 2008 by tomagucci Link to comment Share on other sites More sharing options...
tomagucci Posted October 2, 2008 Author Share Posted October 2, 2008 I think the problem is in the _tickstotime fucntion, in that timerdiff calls upon the former number... is there anyway to get around this? 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