Sign in to follow this  
Followers 0
inwmsn

How to stop looping forever

13 posts in this topic

Hi All

I have some problem that I couldn't figure out how to fix the incomplete process. Here my code

#include <IE.au3>

For $num = 1 to 100

$percent = "%"

$status = $num&$percent

$text = WinGetText("My program")

If StringInStr ($text, $status) Then

MsgBox(0,"","COMPLETE") ;;; whenever if 100% process, it's fine but sometime it stuck between 0-99%

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;for example 67% and stop process forever until I have to reprocess again.

Else

sleep(20) ;;;;;;;;if it is not 100% yet. It will keep looping until 100% But it will loop forever if the process is stucked

EndIf

Next

Can somebody help me. Thanks.

Share this post


Link to post
Share on other sites



ExitLoop

Share this post


Link to post
Share on other sites

Let me make sure I understand what you're asking for. You want a loop that will check to see if a window has a text value of 1-100% in it and if it finds it then do something? Wouldn't you want to do something like if 100% then complete, else if other percent do something else.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The way I see it, that script will terminate after it reaches 100, no matter what.

I'm not quite sure of your problem here...

Edited by VindicatorOmega

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites

Thanks for replying and sorry to make confusing.

I want to capture the stream media's the packet through wm recorder. Each streamming take within 20min. to complete. The process will be identify by 0,1,2,3,..100%. If it is 100% mean that file is captured sucessuly then I can capture another file. But If it is not 100% then it sleep(20) which I use looping to check the status until I got 100%. Anyway if there is not any error during capturing everything would be fine. But often it is stopped during capturing such as 57%, 63%, 89%. Then process still keep looping. Because the status still is not 100%. So it will loop forever. Thus I would like to have a condition state to check status that if it is not 100% within 20 min. Then it will recapture again. May be it should look like this.

For $num = 1 to 100

$percent = "%"

$status = $num&$percent

$text = WinGetText("My program")

$begin = TimerInit()

sleep(1200000)

$dif = TimerDiff($begin)

If StringInStr ($text, $status) Then

MsgBox(0,"","COMPLETE")

Else

sleep(20)

EndIf

If Not StringInStr ($text,$status) And ($dif == 0) Then

MsgBox(0,"","INCOMPLETE")

EndIF

Next

Thanks

Share this post


Link to post
Share on other sites

Nobody helping me..

Share this post


Link to post
Share on other sites

Maybe:

Dim $oldState = WinGetText("My Program") ; Save the old text(and the percentage it's at)
Dim $Timer = TimerInit() ; Start our timer

Do
    Sleep(250)
    If WinGetText("My Program") <> $oldState Then ; Compare the text in the window with the old, stored text
        $Timer = TimerInit() ; Restart the timer, the percentage is increasing(hopefully, unless some other text is changing)
        $oldState = WinGetText("My Program")  ; Resave the old text(and the percentage it's at)
    EndIf
Until StringInStr(WinGetText("My Program"), "100%") Or TimerDiff($Timer) > 1200000 ; Will exit the loop if 100% is detected in the window text, OR if the timer runs out(20 minutes)

If TimerDiff($Timer) > 1200000 Then ; Checks if the timer did run out
    MsgBox(0, "Error", "Capture seems like it has hanged!")
    ;Do something more here?
Else ; otherwise it must've finished!
    MsgBox(0, "Success", "Capture is completed!")
EndIf

Beware that it will wait 20 minutes from the point it hangs(you could decrease the delay it waits by decreasing the value 1200000), which means if it would freeze at 89% then it would sit there and wait for 20 minutes before timing out.. :)

Share this post


Link to post
Share on other sites

Maybe:

Dim $oldState = WinGetText("My Program") ; Save the old text(and the percentage it's at)
Dim $Timer = TimerInit() ; Start our timer

Do
    Sleep(250)
    If WinGetText("My Program") <> $oldState Then ; Compare the text in the window with the old, stored text
        $Timer = TimerInit() ; Restart the timer, the percentage is increasing(hopefully, unless some other text is changing)
        $oldState = WinGetText("My Program")  ; Resave the old text(and the percentage it's at)
    EndIf
Until StringInStr(WinGetText("My Program"), "100%") Or TimerDiff($Timer) > 1200000 ; Will exit the loop if 100% is detected in the window text, OR if the timer runs out(20 minutes)

If TimerDiff($Timer) > 1200000 Then ; Checks if the timer did run out
    MsgBox(0, "Error", "Capture seems like it has hanged!")
    ;Do something more here?
Else ; otherwise it must've finished!
    MsgBox(0, "Success", "Capture is completed!")
EndIf

Beware that it will wait 20 minutes from the point it hangs(you could decrease the delay it waits by decreasing the value 1200000), which means if it would freeze at 89% then it would sit there and wait for 20 minutes before timing out.. :)

Wow!!! It's work !!! Thank you very much !!Free Fly ^^

Share this post


Link to post
Share on other sites

No problemo, hope you learn something from it. :)

Share this post


Link to post
Share on other sites

Hello FreeFly, your code is work like a charm. However when I add the same code for repeat the task after "Else" statement. It won't work as following;

Dim $oldState = WinGetText("My Program") ; Save the old text(and the percentage it's at)

Dim $Timer = TimerInit() ; Start our timer

Do

Sleep(250)

If WinGetText("My Program") <> $oldState Then ; Compare the text in the window with the old, stored text

$Timer = TimerInit() ; Restart the timer, the percentage is increasing(hopefully, unless some other text is changing)

$oldState = WinGetText("My Program") ; Resave the old text(and the percentage it's at)

EndIf

Until StringInStr(WinGetText("My Program"), "100%") Or TimerDiff($Timer) > 1200000 ; Will exit the loop if 100% is detected in the window text, OR if the timer runs out(20 minutes)

If TimerDiff($Timer) > 1200000 Then ; Checks if the timer did run out

MsgBox(0, "Error", "Capture seems like it has hanged!")

;Do something more here?

Else ; otherwise it must've finished!

Dim $oldState = WinGetText("My Program") ; Save the old text(and the percentage it's at)

Dim $Timer = TimerInit() ; Start our timer

Do ;;;;;;--> somthing wrong in this loop. It skip looping even it wasn't reach to 100% yet.

Sleep(250)

If WinGetText("My Program") <> $oldState Then ; Compare the text in the window with the old, stored text

$Timer = TimerInit() ; Restart the timer, the percentage is increasing(hopefully, unless some other text is changing)

$oldState = WinGetText("My Program") ; Resave the old text(and the percentage it's at)

EndIf

Until StringInStr(WinGetText("My Program"), "100%") Or TimerDiff($Timer) > 1200000 ; Will exit the loop if 100% is detected in the window text, OR if the timer runs out(20 minutes)

If TimerDiff($Timer) > 1200000 Then ; Checks if the timer did run out

MsgBox(0, "Error", "Capture seems like it has hanged!")

;Do something more here?

Else ; otherwise it must've finished!

MsgBox(0, "Success", "Capture is completed!")

EndIf

EndIf

Do I miss somthing. Please help Thanks.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Try this:

Dim $oldState
Dim $Timer

For $i = 1 To 4; Do this for 4 times
    $oldState = WinGetText("My Program")
    $Timer = TimerInit()
    Do
        Sleep(250)
        If WinGetText("My Program") <> $oldState Then
            $Timer = TimerInit()
            $oldState = WinGetText("My Program")
        EndIf
    Until StringInStr(WinGetText("My Program"), "100%") Or TimerDiff($Timer) > 1200000 Or Not WinExists("My Program")
    
    If TimerDiff($Timer) > 1200000 Then
        MsgBox(0, "Error", "Capture seems like it has hanged!")
        ;Do something more here?
    Else
        ;Do something more here?
    EndIf
    
    Do
        Sleep(250)
    Until Not StringInStr(WinGetText("My Program"), "100%") ; this will wait untill the window doesn't have 100% in its text
Next

It needs to wait untill it doesn't have 100% in its text before the next iteration takes place, otherwise the window would still have 100% inside its text, and finish the loop instantly.

Edited by FreeFry

Share this post


Link to post
Share on other sites

Perfect !!!!! It work great!! Thanks again FreeFly

Share this post


Link to post
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
Sign in to follow this  
Followers 0