R4z0r Posted May 3, 2013 Share Posted May 3, 2013 Hi there I am using a GUI with the onevent mode: #include <Date.au3> Local $Starttime = IniRead("settings.ini", "SectionstartTime", "Starttime", "Start Time Note Set") Local $Endtime = IniRead("settings.ini", "SectionendTime", "Endtime", "End Time Note Set") ; Timer related $CurrentTime = _NowTime(4) GUI Stuff ... ... ... ; GUI Events While 1 Sleep(100) ; Check Software Run Time or not Switch @WDAY Case 1,2,3,4,5,6,7 If ($CurrentTime > $StartTime AND $CurrentTime < $EndTime) Then ;SplashTextOn("Software", "Within Time Period: Running.", -1, -1, -1, -1, 3, "", 24) ;Sleep(3000) ;SplashOff() GUISetState(@SW_SHOW) ElseIf ($CurrentTime < $StartTime AND $CurrentTime > $EndTime) Then ;MSGBOX(0,"Software in Pause Mode","From "&$StartTime&" to: "&$EndTime) SplashTextOn("Software", "Sleeping...", -1, -1, -1, -1, 3, "", 24) Sleep(3000) SplashOff() GUISetState(@SW_HIDE) EndIf EndSwitch WEnd Why is this not working? Link to comment Share on other sites More sharing options...
mikell Posted May 3, 2013 Share Posted May 3, 2013 You should use _DateDiff in your time comparison... Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 Could you show me please how to implement it in my example? Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 Also why is my script not working i don't find a logical error? Link to comment Share on other sites More sharing options...
BrewManNH Posted May 3, 2013 Share Posted May 3, 2013 You only check the current time once at the beginning of the script, the value isn't ever updated. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 Thanks for this info but it doesn't even work when i START the script and i'm "off-hours". Why? Link to comment Share on other sites More sharing options...
mikell Posted May 3, 2013 Share Posted May 3, 2013 (edited) This should work, please test to see if this is what you needLocal $Starttime = "18:04:00" ; IniRead("settings.ini", "SectionstartTime", "Starttime", "Start Time Note Set") Local $Endtime = "18:04:30" ; IniRead("settings.ini", "SectionendTime", "Endtime", "End Time Note Set") $start = StringReplace($Starttime, ":", "") $end = StringReplace($Endtime, ":", "") $hidden = 0 $gui = GuiCreate("") GuiSetState() While 1 Sleep(100) $cur = @HOUR & @MIN & @SEC ; Current Time If $cur > $start AND $cur < $end Then If $hidden = 1 Then $hidden = 0 MSGBOX(0,"Running","From "&$StartTime&" to: "&$EndTime) GUISetState(@SW_SHOW) EndIf ElseIf $cur < $start OR $cur > $end Then If $hidden = 0 Then $hidden = 1 MSGBOX(0,"Pause","From "&$EndTime&" to: "&$StartTime) GUISetState(@SW_HIDE) EndIf EndIf WEndBTW you'd better put this checking stuff in a AdlibRegister Edited May 3, 2013 by mikell Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 Thank you very much for the help! This it is all about helping each other. GREAT! Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 Ooopes.. not working... I get ALWAYS: MSGBOX(0,"Running","From "&$StartTime&" to: "&$EndTime) EVEN when the starttime + endtime are out of the range! Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 I mean GUI always gets hidden even when it is not in the starttime and endtime range! Link to comment Share on other sites More sharing options...
mikell Posted May 3, 2013 Share Posted May 3, 2013 (edited) Hmm I added the seconds to the times (current, start & end) in the code because this makes it much easier to test, so be careful with the time format Did you change something in the code ? The code above (and below) first shows the gui, then hides it if current time is out of the time range, shows it when it comes into the range, and hides it again after the endtime etcLocal $Starttime = "19:34:00" ; IniRead("settings.ini", "SectionstartTime", "Starttime", "Start Time Note Set") Local $Endtime = "19:34:30" ; IniRead("settings.ini", "SectionendTime", "Endtime", "End Time Note Set") $start = StringReplace($Starttime, ":", "") $end = StringReplace($Endtime, ":", "") $hidden = 0 ; gui is visible $gui = GuiCreate("") GuiSetState() While 1 Sleep(100) $cur = @HOUR & @MIN & @SEC ; get current time ( format hhmmss ) If $cur > $start AND $cur < $end Then ; if in the range If $hidden = 1 Then ; if gui is hidden $hidden = 0 ; show it MSGBOX(0,"Running","From "&$StartTime&" to: "&$EndTime) GUISetState(@SW_SHOW) EndIf ElseIf $cur < $start OR $cur > $end Then ; if out of the range If $hidden = 0 Then ; if gui is visible $hidden = 1 ; hide it MSGBOX(0,"Pause","From "&$EndTime&" to: "&$StartTime) GUISetState(@SW_HIDE) EndIf EndIf WEnd Edited May 3, 2013 by mikell Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 (edited) Try it. It doesnt work on starting the script and it also doesnt "switcht" e.g. from hide to show WHILE running the script :-(I understand your code and it SHOULD work but it doesnt :-(Also:$start = StringReplace($Starttime, ":", "") $end = StringReplace($Endtime, ":", "")Shoudnt this be:$start = StringReplace($Starttime, ":", "") $end = StringReplace($Endtime, ":", ":", "") Edited May 3, 2013 by R4z0r Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 The Stringreplace is the problem: it returns for starttime e.g. 85 ??????? Strange!! Link to comment Share on other sites More sharing options...
mikell Posted May 3, 2013 Share Posted May 3, 2013 (edited) No, StringReplace() replaces all occurences of the searchstring (default) Put some ConsoleWrite inside the code to note it Otherwise, tricky... I really don't understand why it doesn't work for you. Did you modify something in the code I wrote ? Edit StringReplace("19:34:00", ":", "") => 193400 What did you write for $Starttime ? Edited May 3, 2013 by mikell Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 I didnt modify anything. Now I changed to code to: I removed the seconds and did this: While 1 $cur = @HOUR & @MIN ; get current time ( format hhmm ) MsgBox(0,"Time?",$cur,30) MsgBox(0,"Time Check",$start&" "&$end,30) ; main/idle GUI switch statement Switch GUIGetMsg() ; Case $GUI_EVENT_CLOSE ; GUIDelete() ; Exit Case $cur > $start AND $cur < $end If $hidden = 1 Then $hidden = 0 MSGBOX(0,"Running","From "&$StartTime&" to: "&$EndTime) GUISetState(@SW_SHOW) Case $cur < $start OR $cur > $end If $hidden = 0 Then $hidden = 1 MSGBOX(0,"Pause","From "&$EndTime&" to: "&$StartTime) GUISetState(@SW_HIDE) EndSwitch Sleep(10) WEnd This MsgBox(0,"Time Check",$start&" "&$end,30) Returns "85 86" So where is the mistake??? Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 Also we can try Adlib but as far as I know it doesnt allow MSGBOX but we could use Splash Screen?? Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 No, StringReplace() replaces all occurences of the searchstring (default)Put some ConsoleWrite inside the code to note itOtherwise, tricky... I really don't understand why it doesn't work for you. Did you modify something in the code I wrote ?EditStringReplace("19:34:00", ":", "") => 193400What did you write for $Starttime ?e.g. Starttime = "20:00:30" Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 And I have this: ;TEST $StartTime = IniRead("settings.ini", "SectionstartTime", "StartTime", "Start Time Note Set") $EndTime = IniRead("settings.ini", "SectionendTime", "EndTime", "End Time Note Set") ;$start = StringReplace($StartTime, ":", "") $start = $StartTime ;$end = StringReplace($EndTime, ":", "") $end = $EndTime $hidden = 0 ;TEST I tried without iniread like $StartTime = "20:15:00" Link to comment Share on other sites More sharing options...
R4z0r Posted May 3, 2013 Author Share Posted May 3, 2013 OMG!!!! This is the problem? Global $Start = GUICtrlCreateInput($StartTime, 144, 152, 97, 33) GUICtrlSetFont(-1, 16, 400, 0, "Century Schoolbook") GUICtrlSetOnEvent(-1, "StartChange") Global $End = GUICtrlCreateInput($EndTime, 248, 152, 97, 33) GUICtrlSetFont(-1, 16, 400, 0, "Century Schoolbook") GUICtrlSetOnEvent(-1, "EndChange") Link to comment Share on other sites More sharing options...
mikell Posted May 3, 2013 Share Posted May 3, 2013 (edited) I didnt modify anything.Are you joking ?!? the code you posted is VERY different from mine, and contains a lot of mistakesSwitch GUIGetMsg() ... Case $cur => wrongIf $hidden = 1 Then... => you completely changed the content of the conditionsFirst try to run my code WITH NO CHANGES except the time values in the 2 top linesThen ask and/or look at the helpfile before changing the statements Edited May 3, 2013 by mikell 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