Jump to content

Getting loopy with loop


Recommended Posts

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 by aslani

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

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 by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

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 by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

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 by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...