Jump to content

Help with a Loop


Gui
 Share

Recommended Posts

Aye guys, in my bot I'm making, it has a For-To-Next loop. To stop that loop, I want a button to be pressed. So how would I do that? You can do "Func button2() " inside the FTN loop, so what can I do to make it so that if you press a button, it will exit that loop? Please reply.

Gui.

Link to comment
Share on other sites

Aye guys, in my bot I'm making, it has a For-To-Next loop. To stop that loop, I want a button to be pressed. So how would I do that? You can do "Func button2() " inside the FTN loop, so what can I do to make it so that if you press a button, it will exit that loop? Please reply.

Gui.

If _IsPressed("") Then
ExitLoop
EndIf

Search _IsPressed for correct usage.

:)

Edited by UnknownWarrior
Link to comment
Share on other sites

Aye guys, in my bot I'm making, it has a For-To-Next loop. To stop that loop, I want a button to be pressed. So how would I do that? You can do "Func button2() " inside the FTN loop, so what can I do to make it so that if you press a button, it will exit that loop? Please reply.

Gui.

EDIT: I have tried _ispressed, with hotkeys, non work. The loop doesn't allow any functions to work, while it's working. I can't close, or anything. It only stops when a number is reached,( the number of loops.).

Link to comment
Share on other sites

#include <ButtonConstants.au3>

$Test = GUICreate("???", 625, 445, 192, 124)
$Quit = GUICtrlCreateButton("Quit", 360, 232, 153, 65)
GUISetState()

While 1 ;infinte loop
    $msg=GUIGetMsg()
    If $msg = $Quit Then
        ExitLoop
    EndIf
WEnd

I used a while loop (because it is easier), but it has the same effect.

Edited by rliiack

My Projects:Smart Icons

Link to comment
Share on other sites

GuiGetMsg creates a sleep which will slow down your loop. You could use OnEventMode like this.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Global $QuitLoop = 0

$Form1 = GUICreate("Form1", 218, 55, 192, 124)
$Button1 = GUICtrlCreateButton("Kill Loop", 64, 24, 89, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($Button1, "QuitLoop")

While 1
    If $QuitLoop = 1 Then ExitLoop
    Sleep(100)
WEnd

MsgBox(0, "", "The Loop has exited.")

Func QuitLoop()
    Global $QuitLoop = 1
EndFunc   ;==>QuitLoop
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...