aslani Posted April 17, 2008 Share Posted April 17, 2008 (edited) Ok, I created a GUI that would do something at certain time. I've read some scheduler and timer topics but still not exactly what I needed, so here it goes. Obviously I have a While loop to keep my GUI. Now inside that I want to run another loop procedure that checks the current time and at certain time, it will trigger a function that will lopp until the task is complete, then start over again. Here's the part where I get confuse, I'm not sure whether to use another While...WEnd or Do...Until. $calc_hr = GUICtrlRead($time_hr) $calc_mn = GUICtrlRead($time_mn) Do $cur_hr = @HOUR $cur_mn = @MIN Sleep(60000) Until $cur_hr = $time_hr And $cur_mn = $time_mn Run("SomeProgram.exe") WinWait($someprogram) _myFunc($someprogram,733,126) _myFunc($someprogram,916,105) WinClose($someprogram) So what do you think is wrong with this? Edited April 17, 2008 by aslani [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version Link to comment Share on other sites More sharing options...
Squirrely1 Posted April 17, 2008 Share Posted April 17, 2008 (edited) Maybe you just used the wrong variables in the "Until ..." line: $calc_hr = GUICtrlRead($time_hr) $calc_mn = GUICtrlRead($time_mn) Do $cur_hr = @HOUR $cur_mn = @MIN Sleep(60000) Until $calc_hr = $time_hr And $calc_mn = $time_mn ;... I don't see why you would need to nest another loop here - but most folks might just use a While - WEnd loop with an If clause such as this in the loop: If $calc_hr = $time_hr And $calc_mn = $time_mn Then ExitLoop Edited April 17, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
Achilles Posted April 17, 2008 Share Posted April 17, 2008 (edited) Until $calc_hr = $cur_hr And $calc_mn = $cur_mn Edit: $time_hr and $time_mn are going to be numbers that represent the objects that are being read. Edited April 17, 2008 by Achilles My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
aslani Posted April 17, 2008 Author Share Posted April 17, 2008 Until $calc_hr = $cur_hr And $calc_mn = $cur_mn Edit: $time_hr and $time_mn are going to be numbers that represent the objects that are being read. It's official, I'm been working on this for too long, I need a break. Thanks. [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version Link to comment Share on other sites More sharing options...
Squirrely1 Posted April 17, 2008 Share Posted April 17, 2008 (edited) What Achilles is probably saying is that those first two lines of your code should be replaced with something like this: $calc_hr = GUICtrlRead($time_hr) If Not @error Then $calc_hr = StringStripWS($calc_hr, 3) $calc_hr = Number($calc_hr) Else MsgBox(0,"My Program","$calc_hr read error") EndIf $calc_mn = GUICtrlRead($time_mn) If Not @error Then $calc_mn = StringStripWS($calc_mn, 3) $calc_mn = Number($calc_mn) Else MsgBox(0,"My Program","$calc_mn read error") EndIf This does some error checking, removes any unwanted blank spaces from the string returned by GUICtrlRead, and makes sure it is a number and not a string that is used in the comparison done in the Until statement. If you had mathematically changed the values returned from the GUICtrlRead functions - rather than just using them in a mere mathematical comparison operation - the variable type they are stored in would usually be automatically converted to Number. Edited April 17, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
Achilles Posted April 17, 2008 Share Posted April 17, 2008 @Squirrely1: Actually, I just meant that both you and Aslani were both trying to use the @GUI_CtrlId in your until condition instead of the actual hours/minutes. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Squirrely1 Posted April 17, 2008 Share Posted April 17, 2008 (edited) Achilles you are right again. Okay this worked: $calc_hr = GUICtrlRead($time_hr) If Not @error Then $calc_hr = StringStripWS($calc_hr, 3) $calc_hr = Number($calc_hr) Else MsgBox(0,"My Program","$calc_hr read error") EndIf $calc_mn = GUICtrlRead($time_mn) If Not @error Then $calc_mn = StringStripWS($calc_mn, 3) $calc_mn = Number($calc_mn) Else MsgBox(0,"My Program","$calc_mn read error") EndIf Do Sleep(60000) $cur_hr = Number(@HOUR) $cur_mn = Number(@MIN) Until $cur_hr = $calc_hr And $cur_mn = $calc_mn MsgBox(0,"","We have left the loop") ;Run("SomeProgram.exe") ;WinWait($someprogram) ;_myFunc($someprogram,733,126) ;_myFunc($someprogram,916,105) ;WinClose($someprogram) Edited April 17, 2008 by Squirrely1 Das Häschen benutzt Radar 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