Sign in to follow this  
Followers 0
SUB0DH

GUI is displayed and automaticlly terminated.

9 posts in this topic

I've recently learned about AutoIt and thought I'd give it a try. I tried doing some basic mathematical calculations without the GUI and they worked fine. Then, I decided I'll try to make GUI programs so, I made a simple GUI using GUI Designer: Koda 1.7.3.0 . I compiled the code & tried to run it, but after running the compiled program, the GUI is displayed and the program automatically terminates. Following is the code:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

GUICreate("My First GUI", 615, 438, 192, 114)
GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

$lb_title = GUICtrlCreateLabel("Title:", 8, 24, 27, 17)
$lb_des = GUICtrlCreateLabel("Description:", 8, 64, 60, 17)
$input_title = GUICtrlCreateInput("", 72, 24, 377, 21)
$Combo1 = GUICtrlCreateCombo("Combo1", 464, 24, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$input_des = GUICtrlCreateEdit("", 72, 64, 537, 290)
$input_download = GUICtrlCreateInput("", 72, 368, 537, 21)
$bt_save = GUICtrlCreateButton("Save", 448, 400, 75, 25)
$btn_exit = GUICtrlCreateButton("Exit", 536, 400, 75, 25)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    
    Select         
    Case $GUI_EVENT_CLOSE
        GUIDelete()
        Exit
                    
    Case $nmsg=$btn_exit
        GUIDelete()
        Exit
                
    Case=$nmsg=$btn_save
        MsgBox(64,"Save", "Saved!!")
    EndSelect
WEnd

What am I doing wrong here??

And also another question, what is the difference between Compile & Build??

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Your select statement is wrong.

You have mixed Select and Switch syntax and the last Case is totally incorrect.

I suggest you change it all to a Switch.

While 1
    $nMsg = GUIGetMsg()
    
    Switch $nMsg        
        Case $GUI_EVENT_CLOSE, $Btn_exit
            GUIDelete();; Not really needed but doesn't hurt to leave it.
            Exit
        Case $btn_save
            MsgBox(64,"Save", "Saved!!")
    EndSwitch
WEnd

Edit: Corrected a syntax error.

EDIT 2: Since I did this as a Switch, You can combine Case statements so I edited the code again.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

SUB0DH,

Welcome to the AutoIt forum. ;)

Try changing this:

Case $GUI_EVENT_CLOSE

to this:

Case $nMsg = $GUI_EVENT_CLOSE

In a Select structure you need to specify the variable you are checking - it is only in a Switch structure you can omit it. ;)

All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

@M23

Take a look at the last Case as well.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

George,

I had noticed, but as the OP said the code actually ran I assumed they were typos in posting. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Could well be oh brilliant one, but that Select was doomed to fail the way it was written anyway. The reason I suggested the change to Switch in this case is because he is only using 1 variable that he needs to test for, $nMsg, so using a Switch helps prevent errors like that.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

George,

I absolutely agree with you on this, oh wise and ancient one! ;) I always use Switch for the GUIGetMsg loop for exactly that reason.

SUB0DH,

Sorry to hijack your thread - are you happy with what has been suggested by either or both of us? ;)

M23

Edit: Got my Switch/Select mixed up - good job George has sharp eyes (or some good spectacles!) :)

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Careful with the use af the word ancient sunny boy!

Hopefully you meant "I always use Switch for the GUIGetMsg loop for exactly that reason." and not Select. Select will not allow multiple controls on the same Case statement without the use of OR statements. With Switch it's even possible to do things like Case $a To $z, assuming of course those are sequential controls.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

I suggest you change it all to a Switch.

While 1
    $nMsg = GUIGetMsg()
    
    Switch $nMsg        
        Case $GUI_EVENT_CLOSE, $Btn_exit
            GUIDelete();; Not really needed but doesn't hurt to leave it.
            Exit
        Case $btn_save
            MsgBox(64,"Save", "Saved!!")
    EndSwitch
WEnd

Thanks for your suggestion. The code is working with Switch.

SUB0DH,

Welcome to the AutoIt forum. ;)

Try changing this:

Case $GUI_EVENT_CLOSE

to this:

Case $nMsg = $GUI_EVENT_CLOSE

In a Select structure you need to specify the variable you are checking - it is only in a Switch structure you can omit it. ;)

All clear? :)

M23

Thanks for the welcome M23. I was looking for difference between Switch & Select. Now, thanks to you I've found one & also found out what I was doing wrong.

@M23

Take a look at the last Case as well.

George,

I had noticed, but as the OP said the code actually ran I assumed they were typos in posting. :shocked:

M23

Sorry, it was a typo in posting as M23 suspected.

SUB0DH,

Sorry to hijack your thread - are you happy with what has been suggested by either or both of us? :)

M23

Yes. Both of your suggestion works perfectly. Thank you guys once again.

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