Sign in to follow this  
Followers 0
atomman

ContinueLoop in a Func

6 posts in this topic

Normally if i want to abort a Case, i'd just use ContinueLoop. How would you do this if ContinueLoop is in a Func outside the loop?

It doesn't have to be ContinueLoop that is used, i just need to abort the Case.

Share this post


Link to post
Share on other sites



ExitLoop([level])

Return

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Normally if i want to abort a Case, i'd just use ContinueLoop. How would you do this if ContinueLoop is in a Func outside the loop?

It doesn't have to be ContinueLoop that is used, i just need to abort the Case.

Can you give more detail of how you want to do this? A small example script would be helpful. There are several ways of addressing this, depending on the details.

A function called from within a loop can not use ContinueLoop or ExitLoop inside the function, unless it has its own loop. Generally I would check the return value or @Error from the UDF call and then call ContinueLoop or ExitLoop accordingly. Again more details would be helpful.

Edited by Nutster

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

Here ye go...

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $Button_HlLnk
            _GoApp(); switch to App
        ; remainder of Case 
EndSwitch

Func _GoApp()
    If $Var = 1 Then
        MsgBox(262144, "Error!", "App not found!")
    ; ### substitute for ContinueLoop  goes here ###
    Else
        WinActivate($App)
        WinWaitActive($App)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I don't see why the code you have is a problem anyway (did you try using Return?), but you could wrap it in a once-only loop.

Func _GoApp()
  Do
    If $Var = 1 Then
        MsgBox(262144, "Error!", "App not found!")
        ContinueLoop ; Or maybe ExitLoop would be more appropriate, not sure what you're wanting exactly, so experiment
    Else
        WinActivate($App)
        WinWaitActive($App)
    EndIf
  Until True
EndFunc
Edited by Saunders

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I don't see why the code you have is a problem anyway (did you try using Return?), but you could wrap it in a once-only loop.

I didn't see a problem either, but SciTE warns on ContinueLoop being outside a loop, even though technically it isn't since the func is being called inside a loop, and won't run the script.

So putting it in a a loop of it's own eliminates the SciTE problem, but i'm not getting the expected result. Below i added a MsgBox() that i don't expect to ever run, but it does.

As far as using Return, i think i understand basically what it's for, but i don't understand how to use it in this instance. I also tried ExitLoop in place of ContinueLoop and still get the MsgBox.

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $Button_HlLnk
            _GoApp(); switch to App
            MsgBox(0,"","HELLO!")   ; ### not expecting to see this ###
            ; remainder of Case
        
        ; next Case
EndSwitch

Func _GoApp()
    Do
        If $Var = 1 Then
            MsgBox(262144, "Error!", "App not found!")
            ContinueLoop
        Else
            WinActivate($App)
            WinWaitActive($App)
        EndIf
    Until True
EndFunc
Edited by atomman

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