Sign in to follow this  
Followers 0
DanielDaniel

Button won't fire

6 posts in this topic

#1 ·  Posted (edited)

Why won't the button on my GUI call the function? Here's the relevant parts of the code:

$BtnAdd = GUICtrlCreateButton("Add", 305, 7, 50, 49)

$BtnStart = GUICtrlCreateButton("Start", 354, 7, 50, 49)

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $BtnAdd

Case $msg = $BtnStart

Call RunApps()

EndSelect

WEnd

Thanks!

Edited by DanielDaniel

Share this post


Link to post
Share on other sites



Thanks for the quick reply, but still no use. I have reduced the code to this:

While 1

$msg = GUIGetMsg()

If $msg <> 0 Then msgbox(0, "hj", $msg)

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $BtnAdd

MsgBox(0, "hh", "hh")

EndSelect

WEnd

But the msgbox never fires as I suspect that $msg never has a value other than 0.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I've added a gui to your script and a message to the RunApps() function, to test it. 

#include <GUIConstantsEx.au3>

GUICreate("GUI", 600, 400)

$BtnAdd = GUICtrlCreateButton("Add", 305, 7, 50, 49)
$BtnStart = GUICtrlCreateButton("Start", 354, 7, 50, 49)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $BtnAdd

        Case $msg = $BtnStart
            RunApps()
    EndSelect
WEnd

Func RunApps()
    MsgBox(0,"mnbvbv","mnbvmnbbv")
EndFunc

Maybe you have a problem with your other part of the script.

[edit] Please use "[autoit]" tags when you post your code. It's more "readable" because of the syntax highlighting.

Edited by taietel

Share this post


Link to post
Share on other sites

Hmm, so it must be a problem elsewhere in the code because when I adapt your example to include the rest of my code, the button presses are ignored.

Any suggestions on how to debug this? I have 300 lines of code so far...

Thanks!

Share this post


Link to post
Share on other sites

Just to close the loop, I solved this problem. I had put the below line in my code, meaning that the buttons were now event driven (I actually prefer this) rather than using the msg$ and Do/Until option.

Opt("GUIOnEventMode", 1)

Simply adding the event to the button with the below command solved the problem.

GUICtrlSetOnEvent($BtnStart, "RunApps")

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