Sign in to follow this  
Followers 0
pete

GUIGetMsg() inside a sub loop

5 posts in this topic

Hi all,

I have a small window with two buttons, one which starts the script, and the other which is supposed to stop it. The Start button starts a function, which just just spits out some text to notepad in a For/Next loop. The Stop button sets a flag to False, which I would then stop the Start button function.

The problem is, GUIGetMsg() doesn't appear to be functioning within the sub loop, at least my Stop case never seems to get called, and my window won't close.

Here's an abbreviated version of the code:

CODE
While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Case $msg = $Button_1

If $isactive = True Then

For $x = 1 To $max

; do something

Next

EndIf

Case $msg = $Button_2

$isactive = False

MsgBox(0, 'Testing', 'Button 2 was pressed')

EndSelect

WEnd

I'm not quite sure what I'm missing here. I was hoping maybe someone could help me out?

Thanks, Pete

Share this post


Link to post
Share on other sites



Hi all,

I have a small window with two buttons, one which starts the script, and the other which is supposed to stop it. The Start button starts a function, which just just spits out some text to notepad in a For/Next loop. The Stop button sets a flag to False, which I would then stop the Start button function.

The problem is, GUIGetMsg() doesn't appear to be functioning within the sub loop, at least my Stop case never seems to get called, and my window won't close.

Here's an abbreviated version of the code:

I'm not quite sure what I'm missing here. I was hoping maybe someone could help me out?

Thanks, Pete

ok so let me try to understand what you want, you have a gui that has 2 buttons, one staers script other stops, your problem is when you click the stop button it doesnt stop right?

if i got this right then try instead of For/next try to do/until

while 1
If $isactive = True Then
do
;you script here
until $isactive = false
wend

while 2
$msg = guigetmsg()
select 
case $msg = $GUI_EVENT_CLOSE
case $msg = $buttonstop
$isactive= false
endw

this is just put together from what i thought ya meant so i dont know if its what ur looking for

Share this post


Link to post
Share on other sites

That's essentially right, two buttons, one starts the loop, the other to stop.

It seems, even with your code, that the stop button never gets called. I put a msgbox in there, and it's ignored. The X to close the window in the top right, also won't work, I have to manually kill the process in order to get the script to stop running.

Share this post


Link to post
Share on other sites

Hi all,

I have a small window with two buttons, one which starts the script, and the other which is supposed to stop it. The Start button starts a function, which just just spits out some text to notepad in a For/Next loop. The Stop button sets a flag to False, which I would then stop the Start button function.

The problem is, GUIGetMsg() doesn't appear to be functioning within the sub loop, at least my Stop case never seems to get called, and my window won't close.

Here's an abbreviated version of the code:

CODE
While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Case $msg = $Button_1

If $isactive = True Then

For $x = 1 To $max

; do something

Next

EndIf

Case $msg = $Button_2

$isactive = False

MsgBox(0, 'Testing', 'Button 2 was pressed')

EndSelect

WEnd

I'm not quite sure what I'm missing here. I was hoping maybe someone could help me out?

Thanks, Pete

Something like this should do it.

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        Case $msg = $Button_1
            If $isactive = True Then
                For $x = 1 To $max
                ; do something
                    $msg = GuiGetMsg()
                    If $msg = $Button_2 Then
                         ConsoleWrite"Button_2 pressed" & @CR)
                        $Active = False
                        ExitLoop
                    EndIf
                Next
            EndIf
        Case $msg = $Button_2
            $isactive = False
            MsgBox(0, 'Testing', 'Button 2 was pressed')
    EndSelect
WEnd

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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