Jump to content
Sign in to follow this  
Jester009

Continueloop Problem

Recommended Posts

Jester009

Hi guys,

I'm trying to call "ContinueLoop" by a button. But I can't get it working. I have tried my best but it doesn't seem to work. :D

Sample code is posted. Any help is deeply appreciated...

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 297, 197, 193, 125)
$Label1 = GUICtrlCreateLabel("Number", 64, 40, 149, 33, $SS_CENTER)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Button1", 56, 96, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Button2", 168, 96, 75, 25, 0)
GUICtrlSetOnEvent(-1, "breakLoop")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    GUISetOnEvent($GUI_EVENT_CLOSE, "closeEvent")
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            incNum()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func incNum()
    Opt("GUIOnEventMode",1)
    For $i = 0 To 20
        GUICtrlSetData($Label1, $i)
        Sleep(10000)
    Next
    Opt("GUIOnEventMode",0)
    MsgBox(0, "Status", "Done")
EndFunc

Func closeEvent()
    Exit
EndFunc

Func breakLoop()
    While 1
        ContinueLoop 2
    WEnd
EndFunc

Thanks in advance

Jester009

Edited by Jester009

Share this post


Link to post
Share on other sites
d4rk

you can't use continueloop outside the loop


[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites
Jester009

you can't use continueloop outside the loop

Yes, That's why I used ContinueLoop 2 (two levels) Bur seems that does not work.

Any other method to achieve what I'm trying??

:D

Share this post


Link to post
Share on other sites
MHz

Use a variable to flag a ContinueLoop or ExitLoop.

#include <GUIConstants.au3>
Global $breakloop
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 297, 197, 193, 125)
$Label1 = GUICtrlCreateLabel("Number", 64, 40, 149, 33, $SS_CENTER)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Start", 26, 96, 75, 25, 0)
$Button2 = GUICtrlCreateButton("BreakLoop", 138, 96, 75, 25, 0)
GUICtrlSetOnEvent(-1, "_breakLoop")
$Button2 = GUICtrlCreateButton("ContinueLoop", 218, 96, 75, 25, 0)
GUICtrlSetOnEvent(-1, "_continueloop")
$label2 = GUICtrlCreateLabel("", 20, 150, 160, 30)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    GUISetOnEvent($GUI_EVENT_CLOSE, "closeEvent")
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            incNum()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func incNum()
    Opt("GUIOnEventMode",1)
    For $i = 0 To 20
        If $breakloop = 1 Then
            $breakloop = 0
            GUICtrlSetData($label2, "")
            ContinueLoop
        ElseIf $breakloop = 2 Then
            $breakloop = 0
            GUICtrlSetData($label2, "")
            ExitLoop
        EndIf
        GUICtrlSetData($Label1, $i)
        Sleep(5000)
    Next
    Opt("GUIOnEventMode",0)
    MsgBox(0, "Status", "Done")
EndFunc

Func closeEvent()
    Exit
EndFunc

Func _continueLoop()
    $breakloop = 1
    GUICtrlSetData($label2, "Continue Loop")
EndFunc

Func _breakLoop()
    $breakloop = 2
    GUICtrlSetData($label2, "Break out of Loop")
EndFunc

:D

Share this post


Link to post
Share on other sites
Jester009

Thanks MHz, Your code seems to do the trick. But it does not save me the sleep time that I have put there.

What I want is a method to skip the Sleep(10000) part when I want to. (Sometimes I want to wait the whole 10 seconds, sometimes I don't want)

Any method??

:D

Share this post


Link to post
Share on other sites
MHz

OK, then change the sleep pattern with another For loop conditionally checking for setting of $breakloop

#include <GUIConstants.au3>
Global $breakloop
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 297, 197, 193, 125)
$Label1 = GUICtrlCreateLabel("Number", 64, 40, 149, 33, $SS_CENTER)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Start", 26, 96, 75, 25, 0)
$Button2 = GUICtrlCreateButton("BreakLoop", 138, 96, 75, 25, 0)
GUICtrlSetOnEvent(-1, "_breakLoop")
$Button2 = GUICtrlCreateButton("ContinueLoop", 218, 96, 75, 25, 0)
GUICtrlSetOnEvent(-1, "_continueloop")
$label2 = GUICtrlCreateLabel("", 20, 150, 160, 30)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    GUISetOnEvent($GUI_EVENT_CLOSE, "closeEvent")
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            incNum()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func incNum()
    Opt("GUIOnEventMode",1)
    For $i = 0 To 20
        If $breakloop = 1 Then
            $breakloop = 0
            GUICtrlSetData($label2, "")
            ContinueLoop
        ElseIf $breakloop = 2 Then
            $breakloop = 0
            GUICtrlSetData($label2, "")
            ExitLoop
        EndIf
        GUICtrlSetData($Label1, $i)
        ; Conditinal sleep
        For $j = 1 To 40
            If $breakloop Then
                ExitLoop
            EndIf
            Sleep(250)
        Next
    Next
    Opt("GUIOnEventMode",0)
    MsgBox(0, "Status", "Done")
EndFunc

Func closeEvent()
    Exit
EndFunc

Func _continueLoop()
    $breakloop = 1
    GUICtrlSetData($label2, "Continue Loop")
EndFunc

Func _breakLoop()
    $breakloop = 2
    GUICtrlSetData($label2, "Break out of Loop")
EndFunc
Edited by MHz

Share this post


Link to post
Share on other sites
Jester009

WOW. Thanks a lot MHz. It's really a nice move to put sleep inside another for loop.

Solves my problem. :D

Thanks again.....

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  

×