Jump to content
Sign in to follow this  
DanielTyrkiel

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

Recommended Posts

DanielTyrkiel

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

Share this post


Link to post
Share on other sites
water

Replace

Case $nMsg = $Button1
with
Case $Button1


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
DanielTyrkiel

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

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
DanielTyrkiel

WOW, this caught me by surprise! :oops:

Many thanks

More to learn...

Share this post


Link to post
Share on other sites
water

Glad to be of service :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

×