Jump to content

What am I missing?


Trax
 Share

Recommended Posts

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...