Sign in to follow this  
Followers 0
dickjones007

button to end loop

9 posts in this topic

how can i make a button to end the

While 1

Wend

loop

Share this post


Link to post
Share on other sites



dickjones,

Do you seriously expect any concrete help with a question like that? :D

How do you get into the loop? Do you have a GUI to hold the button? Any number of questions spring to mind. :oops:

How about posting the code you are using and giving a bit more explanation. :rip:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

i thought it was something more of a general thing

this is the code for which i need the button

While 1
    $changepixel = PixelChecksum(320, 100, 320, 100)
    While $changepixel = PixelChecksum(320, 100, 320, 100)
     Sleep(1000)
    WEnd
    $randtim = Random(1300, 4800, 1)
    Sleep($randtim)
    $checksum0 = PixelChecksum(89, 76, 130, 103)
    $checksum1 = PixelChecksum(160, 78, 201, 105)
    $checksum2 = PixelChecksum(202, 78, 243, 105)
    $checksum3 = PixelChecksum(244, 78, 285, 105)
    $checksum4 = PixelChecksum(286, 78, 327, 105)
;~ MsgBox(0, 0, $checksum0)
;~ MsgBox(0, 0, $checksum1)
;~ MsgBox(0, 0, $checksum2)
;~ MsgBox(0, 0, $checksum3)
;~ MsgBox(0, 0, $checksum4)
    $randomx1 = Random(162, 198, 1)
    $randomx2 = Random(203, 241, 1)
    $randomx3 = Random(245, 283, 1)
    $randomx4 = Random(287, 324, 1)
    $randomy1 = Random(79, 104, 1)
    If $checksum0 = $checksum1 Then
     Sleep(1000)
     MouseClick("primary", $randomx1, $randomy1)
    ElseIf $checksum0 = $checksum2 Then
     Sleep(1000)
     MouseClick("primary", $randomx2, $randomy1)
    ElseIf $checksum0 = $checksum3 Then
     Sleep(1000)
     MouseClick("primary", $randomx3, $randomy1)
    ElseIf $checksum0 = $checksum4 Then
     Sleep(1000)
     MouseClick("primary", $randomx4, $randomy1)
    EndIf
   WEnd

this is a part of a whole GUICreate i am making

Share this post


Link to post
Share on other sites

dickjones,

If some condition then exitloop, or,

some hotkey, or,

some accelerator key, or,

some event...

Lot's of stuff in the help files

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

dickjones,

Is the Help file example for GUICtrlCreateButton that difficult to understand? :oops:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hButton = GUICtrlCreateButton("Exit Loop", 10, 10, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            ExitLoop ; Exit the loop
    EndSwitch

WEnd

MsgBox(0, "Here", "I have exited the loop")

All clear? :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

yes but will the code run until it comes to exit button code or will the code stop immediately after the button is pushed?

Share this post


Link to post
Share on other sites

dickjones,

If you put the Switch GUIGetMsg() structure in the While...WEnd loop the code will run until the message queue is polled. I see you have a lot of Sleep lines in yoru loop - you can speed up the polling by replacing these lines by somethin gliek this:

; Sleep(1000)

; Get a timestamp
$iBegin = TimerInit() ; Until the time reaches the required number of msec since the timestamp
While TimerDiff($iBegin) < 1000
    ; Poll the message queue
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            ExitLoop 2 ; Exit both loops - this one and the external one
    EndSwitch
WEnd

This way the script remains responsive during the delay period of the internal loop and a button click is honoured as soon as possible. :oops:

All clear? :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

While 1

$changepixel = PixelChecksum(320, 100, 320, 100)
    While $changepixel = PixelChecksum(320, 100, 320, 100)
     Sleep(1000)
    WEnd
    $randtim = Random(1300, 4800, 1)
    Sleep($randtim)

    $checksum0 = PixelChecksum(89, 76, 130, 103)
    $checksum1 = PixelChecksum(160, 78, 201, 105)
    $checksum2 = PixelChecksum(202, 78, 243, 105)
    $checksum3 = PixelChecksum(244, 78, 285, 105)
    $checksum4 = PixelChecksum(286, 78, 327, 105)
    $randomx1 = Random(162, 198, 1)
    $randomx2 = Random(203, 241, 1)
    $randomx3 = Random(245, 283, 1)
    $randomx4 = Random(287, 324, 1)
    $randomy1 = Random(79, 104, 1)
    If $checksum0 = $checksum1 Then
     Sleep(1000)
     MouseClick("primary", $randomx1, $randomy1)
    ElseIf $checksum0 = $checksum2 Then
     Sleep(1000)
     MouseClick("primary", $randomx2, $randomy1)
    ElseIf $checksum0 = $checksum3 Then
     Sleep(1000)
     MouseClick("primary", $randomx3, $randomy1)
    ElseIf $checksum0 = $checksum4 Then
     Sleep(1000)
     MouseClick("primary", $randomx4, $randomy1)
    EndIf
    Switch GUIGetMsg()
     Case $GUI_EVENT_CLOSE
      Exit
     Case $GUI_Button_exitloop
      ExitLoop 2
    EndSwitch
   WEnd

am i getting something wrong here?

i keep pressing exitloop button but the code still continues. how so?

btw i am beginner here. for now i will keep my Sleep lines and will consider your timerinit suggestion for something else. thanx for that.

also i mostly take parts of finished codes and put it together for something i need. but i am learning that way.

just dont hate me for my newb question and problems :D

Share this post


Link to post
Share on other sites

dickjones,

dont hate me for my newb question and problems

Of course not. :D

The problem with your loop is that the script becomes totally unresponsive during the Sleep lines - absolutely nothing happens at all. You have to wait until you get to the GUIGetMsg line before your button press will be seen and acted upon. That is why I suggested replacing them with TimerInit/Diff loops - these give you a pretty instant response. You can write a short function to hold the Timer loop which makes it very easy to code - like this: :rip:

While 1

    $changepixel = PixelChecksum(320, 100, 320, 100)
    While $changepixel = PixelChecksum(320, 100, 320, 100)
        ; Wait for a sec - but look for the button being pressed by using the function
        If _My_Sleep(1000) = True  Then
            ; If it was then exit the 2 loops and carry on
            ExitLoop 2
        EndIf
    WEnd
    $randtim = Random(1300, 4800, 1)
    If _My_Sleep($randtim) = True Then
        ; Only the 1 loop to exit this time
        ExitLoop
    EndIf
    
    $checksum0 = PixelChecksum(89, 76, 130, 103)
    $checksum1 = PixelChecksum(160, 78, 201, 105)
    $checksum2 = PixelChecksum(202, 78, 243, 105)
    $checksum3 = PixelChecksum(244, 78, 285, 105)
    $checksum4 = PixelChecksum(286, 78, 327, 105)
    $randomx1 = Random(162, 198, 1)
    $randomx2 = Random(203, 241, 1)
    $randomx3 = Random(245, 283, 1)
    $randomx4 = Random(287, 324, 1)
    $randomy1 = Random(79, 104, 1)
    If $checksum0 = $checksum1 Then
        If _My_Sleep(1000) = True Then
            ExitLoop
        EndIf
        MouseClick("primary", $randomx1, $randomy1)
    ElseIf $checksum0 = $checksum2 Then
        If _My_Sleep(1000) = True Then
            ExitLoop
        EndIf
        MouseClick("primary", $randomx2, $randomy1)
    ElseIf $checksum0 = $checksum3 Then
        If _My_Sleep(1000) = True Then
            ExitLoop
        EndIf
        MouseClick("primary", $randomx3, $randomy1)
    ElseIf $checksum0 = $checksum4 Then
        If _My_Sleep(1000) = True Then
            ExitLoop
        EndIf
        MouseClick("primary", $randomx4, $randomy1)
    EndIf
    ; And there is no need to check again here as we are doing it often enough as we call the _My_Sleep function
    ;Switch GUIGetMsg()
    ;   Case $GUI_EVENT_CLOSE
    ;       Exit
    ;   Case $GUI_Button_exitloop
    ;       ExitLoop 2
    ;EndSwitch
WEnd

Func _My_Sleep($iDelay)
    
    $iBegin = TimerInit() ; Until the time reaches the required number of msec since the timestamp
    While TimerDiff($iBegin) < $iDelay
        ; Poll the message queue
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $hButton
                Return True ; Tell the main loop the button was pressed and return immediately
        EndSwitch
    WEnd
    ; We are here because the loop has waited for the required time
    ; Tell the main loop the button was not pressed
    Return False

EndFunc

Please ask if you have any questions. :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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