Trax Posted September 18, 2017 Share Posted September 18, 2017 I started playing with Koda today trying to get the hang of GUIs. The below code is generated from Koda but as soon as I put in a second case the GUI only stays open for a second then closes. Having a bad day. I am sure it is something very simple I just can't figure out what. Pulling my hair out..... #include <GUIConstantsEx.au3> Local $ButtonSet, $ButtonQuit,$Form, $Label, $Input, $nMsg ;--=== main line ===--; Set_Gui() While 1 $nMsg = GUIGetMsg() Switch $nMsg() Case $GUI_EVENT_CLOSE Exit Case $ButtonQuit Beep() Case $ButtonSet Beep() EndSwitch WEnd Exit ;--=== main GUI window ===--; Func Set_GUI() $Form = GUICreate("Set OBD Signatures", 615, 437, -870, 249) $ButtonSet = GUICtrlCreateButton("Set", 136, 256, 75, 25) $ButtonExit = GUICtrlCreateButton("Exit", 440, 264, 75, 25) $Label = GUICtrlCreateLabel("Serial Number: ", 120, 128, 76, 17) $Input = GUICtrlCreateInput("Input", 240, 128, 121, 21) GUISetState(@SW_SHOW) EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 18, 2017 Moderators Share Posted September 18, 2017 Trax, You have declared $ButtonQuit but use $ButtonExit to store the button ControlID. As a result $ButtonQuit has no declared value and AutoIt treats it as 0, which is the default return from GUIGetMsg and so fires that case on the first pass. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
vestanpance3110 Posted September 18, 2017 Share Posted September 18, 2017 11 minutes ago, Trax said: I started playing with Koda today trying to get the hang of GUIs. The below code is generated from Koda but as soon as I put in a second case the GUI only stays open for a second then closes. Having a bad day. I am sure it is something very simple I just can't figure out what. Pulling my hair out..... #include <GUIConstantsEx.au3> Local $ButtonSet, $ButtonQuit,$Form, $Label, $Input, $nMsg ;--=== main line ===--; Set_Gui() While 1 $nMsg = GUIGetMsg() Switch $nMsg() Case $GUI_EVENT_CLOSE Exit Case $ButtonQuit Beep() Case $ButtonSet Beep() EndSwitch WEnd Exit ;--=== main GUI window ===--; Func Set_GUI() $Form = GUICreate("Set OBD Signatures", 615, 437, -870, 249) $ButtonSet = GUICtrlCreateButton("Set", 136, 256, 75, 25) $ButtonExit = GUICtrlCreateButton("Exit", 440, 264, 75, 25) $Label = GUICtrlCreateLabel("Serial Number: ", 120, 128, 76, 17) $Input = GUICtrlCreateInput("Input", 240, 128, 121, 21) GUISetState(@SW_SHOW) EndFunc There's several things wrong Your Button's names don't match. $ButtonExit vs $ButtonQuit Don't call it $ButtonExit. Also, remove the () from Switch $nMsg() This is why it keeps closing. Hope that helps. Link to comment Share on other sites More sharing options...
Trax Posted September 18, 2017 Author Share Posted September 18, 2017 (edited) Thanks Melba23 and vestanpance3110. Long day. Edited September 18, 2017 by Trax Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now