Sign in to follow this  
Followers 0
Juggernaut

Loop won't stop?

4 posts in this topic

So for some reason (ive tried a few ways) my loop won't stop. Here is my code:

While 1
     $msg = GUIGetMsg()
     Select
         Case $msg = $GUI_EVENT_CLOSE
             ExitLoop
         Case $msg = $btn_start
$user_input = GuiCtrlRead($txt_user)
$active = true
StartTimer()
Case $msg = $btn_stop
$active = false
Case $msg = $btn_info
MsgBox(0, "Information", "test")
     EndSelect
WEnd
GUIDelete()
EndFunc

Func StartTimer()
While 1
if $active = True Then
;do stuff
Else
;STOP LOOP? - $active defined above should stop it?
EndIf
WEnd
EndFunc

If anyone has some ideas, it would be appreciated

**sorry about the formatting of the code, for some reason it did that when i pasted it onto here

Share this post


Link to post
Share on other sites



Juggernaut,

$active does not stop your endless loop (while 1).

just add an ExitLoop in the else section of your StartTimer() function.


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Yeah I just tried using ExitLoop, but for some reason it doesn't do anything besides 'freezing' my program. I can edit the text control, but using the buttons, or trying to close it doesn't work.

While 1
     $msg = GUIGetMsg()
     Select
         Case $msg = $GUI_EVENT_CLOSE
             ExitLoop
         Case $msg = $btn_start
$user_input = GuiCtrlRead($txt_user)
     if $user_input = "" Then
     MsgBox(0, "Error", "Invalid")
     Else
     $active = true
     Start()
     EndIf
Case $msg = $btn_stop
$active = false
Case $msg = $btn_info
MsgBox(0, "Information", "test")
     EndSelect
WEnd
GUIDelete()
EndFunc
Func Start()
While 1
if $active = true Then
;do stuff
Else
ExitLoop
EndIf
WEnd
EndFunc
Func quit()
Exit
EndFunc

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Juggernaut,

this should work...

While 1
    if $active = true Then
        ;do stuff
        ;Set $avtive to false
        ; OR cast an ExitLoop here
    Else
        ExitLoop
    EndIf
WEnd

Btw. you can use [ autoit] and [ /autoit] tags to enclose your code.

Edited by hannes08

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

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