Jump to content

[Solved] Message appears in a loop but button is not pressed


Recommended Posts

SOLVED: I was using switch, which required just $Button1, NOT $nMsg = $Button1

Thanks Water!

Hi,

This is my first stab at GUI. I'm using KODA.

I'm trying to get a button to work so that when I press it, a future function can use the information that I input using the calendar and input lines.

The problem I get is that the message box (used only for testing) shows up immediately after starting the script - it doesn't wait for the "case" when the button is pressed.

What am I doing wrong? I can't find a straight answer in forums and spent over two hours trying to get it to work.

Here's my code:

#include
#include
#include
#include
#include
#include


#region ### START Koda GUI section ### Form=C:\Documents and Settings\daniel.tyrkiel\My Documents\scripts\Enter order info.kxf
$Form1 = GUICreate("Purchase Order Entry", 353, 364, 192, 124)
$Date1 = GUICtrlCreateDate("2012/10/12 07:58:56", 32, 24, 129, 25, $DTS_SHORTDATEFORMAT)
$Label1 = GUICtrlCreateLabel("choose delivery date", 200, 24, 102, 17)
$eWorksOrder = GUICtrlCreateInput("W053330", 32, 184, 129, 21) ;input for works order number
$Label2 = GUICtrlCreateLabel("input works order number", 200, 184, 123, 17)
$Customer = GUICtrlCreateInput("TILDA", 32, 224, 129, 21, $ES_UPPERCASE) ;input customer
$JobNumber = GUICtrlCreateInput("XR45", 32, 264, 129, 21) ;input machine type and week of completion
$Label3 = GUICtrlCreateLabel("input customer name ", 200, 224, 105, 17)
$Label4 = GUICtrlCreateLabel("input type machine and week", 200, 264, 143, 17)
$Button1 = GUICtrlCreateButton("Start", 32, 312, 97, 25)
;GUICtrlSetOnEvent(-1, $Button1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

;Local $date1trimmed = StringTrimRight(GUICtrlRead($Date1), 4)
;Local $hndl = MsgBox(0, "Date", $date1trimmed & "12")



While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $nMsg = $Button1
MsgBox(0, "", "you pressed me")
EndSwitch
WEnd
Edited by DanielTyrkiel
Link to comment
Share on other sites

Replace

Case $nMsg = $Button1
with
Case $Button1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thank you, this worked.

Is there an updated help file then?

This is the official example from the help file that I based it on:

#include 

Example()

Func Example()
Local $Button_1, $Button_2, $msg
GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered

Opt("GUICoordMode", 2)
$Button_1 = GUICtrlCreateButton("Run Notepad", 10, 30, 100)
$Button_2 = GUICtrlCreateButton("Button Test", 0, -1)

GUISetState() ; will display an dialog box with 2 button

; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button_1
Run('notepad.exe') ; Will Run/Open Notepad
Case $msg = $Button_2
MsgBox(0, 'Testing', 'Button 2 was pressed') ; Will demonstrate Button 2 being pressed
EndSelect
WEnd
EndFunc ;==>Example

Many thanks Water

Link to comment
Share on other sites

The example uses Select whereas your script uses Switch. So the example is correct. Your script was just using a wrong syntax for Switch.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Glad to be of service :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...