Sign in to follow this  
Followers 0
cypher175

Restart a loop from the beginning if a function fails..?

20 posts in this topic

is there anyway to restart a loop (While 1 - Wend) from the beginning if a function fails inside of that loop..??

Share this post


Link to post
Share on other sites



is there anyway to restart a loop (While 1 - Wend) from the beginning if a function fails inside of that loop..??

Depends on how your function is written. If it returns an error code then just use something like this

While 1
    _MyFunction()
    If @Error Then ContinueLoop
Wend

Func _MyFunction()
    If @UserName <> "XYZ" Then Return SetError(1)
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

is there anyway to restart a loop (While 1 - Wend) from the beginning if a function fails inside of that loop..??

Continueloop

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Depends on how your function is written. If it returns an error code then just use something like this

While 1
    _MyFunction()
    If @Error Then ContinueLoop
Wend

Func _MyFunction()
    If @UserName <> "XYZ" Then Return SetError(1)
EndFunc
Small addition.

:D

While 1
    _MyFunction()
    If @Error Then ContinueLoop
    ExitLoop
Wend
Edited by Yashied

Share this post


Link to post
Share on other sites

I didn't do that because he might have something else to do and he wants to keep checking until he gets a match. Besides the way I have it demonstrates the way continuous loops work. :D


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

???

:D

You are right, I am testing your response :o or until the ExitLoop, Hmm Edited by MHz

Share this post


Link to post
Share on other sites

it doesn't seem to work for my code, is it because its inside a (DO-UNTIL) Loop..??

While 1

Do

Sleep(10000)

_IEAction ($IE, "refresh")

If @Error Then ContinueLoop

ExitLoop

_IELinkClickByText($IE, "LINK")

Until Not @error

Wend

Share this post


Link to post
Share on other sites

???

:D

I think he means it won't loop if there is no error and in that he's correct so there would be no reason to put the function call inside a loop

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

it doesn't seem to work for my code, is it because its inside a (DO-UNTIL) Loop..??

While 1

Do

Sleep(10000)

_IEAction ($IE, "refresh")

If @Error Then ContinueLoop

ExitLoop

_IELinkClickByText($IE, "LINK")

Until Not @error

Wend

Somebody confused you. Take that ExitLoop out of there.

Edit: In your code youu only need the Do Until. Not the While 1 Wend

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

i have other code in between the (While 1-Wend) loop before & after the (DO-UNTIL) loop, but if the _IEAction ($IE, "refresh") function fails inside the DO-UNTIL loop in need to restart the whole (While 1-Wend) loop again from the beginning..

Share this post


Link to post
Share on other sites

Now we are getting to the meat and potatoes of the issue

Use ContinueLoop 2


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

i have other code in between the (While 1-Wend) loop before & after the (DO-UNTIL) loop, but if the _IEAction ($IE, "refresh") function fails inside the DO-UNTIL loop in need to restart the whole (While 1-Wend) loop again from the beginning..

Maybe you want to get following?

While 1
...
    While 1
        Sleep(10000)
        _IEAction ($IE, "refresh")
        If Not @Error Then
            _IELinkClickByText($IE, "LINK")
            If Not @Error Then
                ExitLoop
            EndIf
        EndIf
    WEnd
...
WEnd

Share this post


Link to post
Share on other sites

like this then or what..??

While 1

Do
    Sleep(10000)
    _IEAction ($IE, "refresh")
    If @Error Then ContinueLoop 2 
    _IELinkClickByText($IE, "LINK")
Until Not @error

Wend

becuz i just tried that and got this error

C:\Program Files\AutoIt3\Include\IE.au3 (2847) : ==> The requested action with this object has failed.:
$o_object.document.execCommand("Refresh")
$o_object.document^ ERROR
>Exit code: 1   Time: 17.375

and it exited instead of continuing the script..??

Share this post


Link to post
Share on other sites

Dale would have to verify this but I don't think you even have to handle an error check for the Refresh action. Just follow that line with an _IELoadWait call.

Yashied also has a good method in his reply


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

huh, what are you asking me..??

Share this post


Link to post
Share on other sites

well if the browser window is closed when it goes to refreshed then the script exits.. so how to detect if refresh failed becuase the browser window is absent and then to restart the While 1-Wend loop from the beginning again..??

Share this post


Link to post
Share on other sites

anybody know how to restart the whole while 1 loop if the _IEAction ($IE, "refresh") fails becuz the browser window has been closed..??

Share this post


Link to post
Share on other sites

nobody knows or what..??

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