Sign in to follow this  
Followers 0
jfcby

Buttons Not Working while script is running...

2 posts in this topic

Hi,

While the following script is running none of my button work. How can I get the script to pause, stop, and close using the "For next" statement in the script below?

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>

HotKeySet("{ESC}", "_EX");Exit Script
HotKeySet("{PAUSE}", "_PUhks");Pause Script

Global $Paused, $ci, $i
Local $a1[100]
Local $a2[100]

$a1[1] = "1";Begin
$a1[2] = "20"
$a1[3] = "40"

$a2[1] = "15";End
$a2[2] = "35"
$a2[3] = "55"

Local $msg

    GUICreate("Array Test", 300, 300);Create a centered dialog box 
    
    GUICtrlCreateLabel('Keboard Keys: "Esc" = Exit Script' & @LF & @LF & ' and "Pause/Break" = Pause Script', 30, 5, 175, 50, $SS_CENTER)
    $LBC = GUICtrlCreateLabel("", 10, 75, 25, 25);Label Display Count
    $SR = GUICtrlCreateButton("Start", 40, 75, 50, 20);Start Button
    $PU = GUICtrlCreateButton("Pause", 95, 75, 50, 20);Pause Button
    $SP = GUICtrlCreateButton("Stop", 150, 75, 50, 20);Stop Button
    $Ex = GUICtrlCreateButton("Exit", 205, 75, 50, 20);Exit Button
    
    GUISetState();Displays an empty dialog box

;Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $Ex
                ExitLoop
            Case $msg = $SR;Start Counter
                _SR()
            Case $msg = $PU;Pause Counter
                _PU()
            Case $msg = $SP;Stop Counter
                _SP()
        EndSelect       
    WEnd

Func _Count_ci($ci) 
    For $ci = 1 to 4
        _Count_i($i, $ci)
    Next
    GUICtrlSetData($LBC, "")
EndFunc;==> Main Counter for First "For Next" Statement

Func _Count_i($i, $ci)  
    For $i = $a1[$ci] to $a2[$ci]                       
        Sleep(200)
    ;MsgBox(0,"", $a1[$ci] & " - " & $a2[$ci])
        GUICtrlSetData($LBC, $i)            
    Next
EndFunc;==> Main Counter for Second "For Next" Statement 

Func _SR()
    _Count_ci($ci)
EndFunc;==> Start Counter

Func _SP()
    MsgBox(0,"", "Clicked Stop")
EndFunc;==> Stop Counter

Func _PU()
;Contimue count at same location that $a1[$ci] was  paused.
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc;==> Pause Counter With Button

Func _PUhks()
;Continue count from the $ci value
    
EndFunc;==> Pause Counter With HotKeySet

Func _EX()
    Exit 0
EndFunc;==> Exit Counter

Thank you for your help,

jfcby


Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

That´s normal.

If you use a loop in a function the GUI can´t do it´s work.

You could use GUIOnEventMode instead of the MessageMode

Edited by bluelamp

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