Akshay07 Posted December 29, 2009 Share Posted December 29, 2009 (edited) Note: Sorry for the unclear title, I just found out that I made a mistake when writing it but I can't edit it.It should be Msgbox with timout: ending process when OK is clicked or if Msgbox timesout Hello all,I am trying to do the following:1? Start a program2/ Create a message box with a 10 seconds time out and a OK button3/-a OK button is clicked within 10 seconds, close the programor3/-b OK button is NOT clicked within 1o seconds, close the program after 10 seconds.I tried something like this, and as you can guess, it does not work The program does not get closed when I click on OK within 10 seconds.Run ( "C:\MyProgram.exe" ) $answer = MsgBox ( 262144, "blablabla", "blablablabla", 10) While WinExists ( "blablabla" ) = 1 If $answer = 0 Then ProcessClose ( "MyProgram.exe" ) EndIf WEnd ProcessClose ( "MyProgram.exe" ) Could someone please tell me what is wrong with this script? Edited December 29, 2009 by Akshay07 Link to comment Share on other sites More sharing options...
Developers Jos Posted December 29, 2009 Developers Share Posted December 29, 2009 Look at the helpfile for details but this might help: $answer = MsgBox ( 262144, "blablabla", "blablablabla", 10) Switch $answer Case -1 ; time out Case 6 ; Yes Case 7 ; No EndSelect SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 29, 2009 Moderators Share Posted December 29, 2009 Akshay07, As you have only an OK button, all you need to do is check for the timeout: Run ( "C:\MyProgram.exe" ) If MsgBox ( 262144, "blablabla", "blablablabla", 10) = -1 Then Sleep(10000) ; Time out so wait 10 secs ProcessClose ( "MyProgram.exe" ) 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...
Akshay07 Posted December 29, 2009 Author Share Posted December 29, 2009 (edited) Look at the helpfile for details but this might help: $answer = MsgBox ( 262144, "blablabla", "blablablabla", 10) Switch $answer Case -1 ; time out Case 6 ; Yes Case 7 ; No EndSelect Thanks for your quick answer. I did look at the help file for Msgbox before posting (I try to not bother you guys for nothing whenever possible ) I guess you meant "Select" instead of "switch" ? I tried this (I have only a OK button in my msgbox While WinExists ( "blablabla" ) = 1 Select Case $answer = -1 ; Timeout ProcessClose ( "MyProgram.exe" ) Case $answer = 0 ; OK is clicked ProcessClose ( "MyProgram.exe" ) EndSelect WEnd But it is still not working. Edited December 29, 2009 by Akshay07 Link to comment Share on other sites More sharing options...
Akshay07 Posted December 29, 2009 Author Share Posted December 29, 2009 (edited) Akshay07, As you have only an OK button, all you need to do is check for the timeout: Run ( "C:\MyProgram.exe" ) If MsgBox ( 262144, "blablabla", "blablablabla", 10) = -1 Then Sleep(10000) ; Time out so wait 10 secs ProcessClose ( "MyProgram.exe" ) M23 Thanks. But what I want to do is to close the program as soon as OK is clicked, without having to wait for the timeout. The reason for this is that MyProgram.exe is playing a sound non-stop. So if the user clicks OK, the sound has to stop (therefore, MyProgram.exe has to stop) Edited December 29, 2009 by Akshay07 Link to comment Share on other sites More sharing options...
Developers Jos Posted December 29, 2009 Developers Share Posted December 29, 2009 (edited) No I meant Switch, only made a typo with the EndSwitch. $answer = MsgBox ( 262144, "blablabla", "blablablabla", 10) Switch $answer Case -1 ; time out Case 1 ; Ok Case 6 ; Yes Case 7 ; Yes EndSwitch Try it and get rid of that While loop you posted again. Edited December 29, 2009 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Akshay07 Posted December 29, 2009 Author Share Posted December 29, 2009 (edited) No I meant Switch, only made a typo with the EndSwitch. $answer = MsgBox ( 262144, "blablabla", "blablablabla", 10) Switch $answer Case -1 ; time out Case 1 ; Ok Case 6 ; Yes Case 7 ; Yes EndSwitch Try it and get rid of that While loop you posted again. Still not working $answer = MsgBox ( 262144, "blablabla", "blablablabla", 10) Switch $answer Case -1 ProcessClose ( "MyProgram.exe" ) Case 0 ProcessClose ( "MyProgram.exe" ) EndSwitch $answer can only be -1 or 0 as I have only a OK button Edited December 29, 2009 by Akshay07 Link to comment Share on other sites More sharing options...
Developers Jos Posted December 29, 2009 Developers Share Posted December 29, 2009 ok button returns a 1 as shown in my example! ..and it help to be specific as to what isn't working. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
bogQ Posted December 29, 2009 Share Posted December 29, 2009 @Akshay07 0 is decimal flag for OK button, its not return value, your looking on the wrong line (Remarks) in help file (try Return Value part not remarks) TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Akshay07 Posted December 29, 2009 Author Share Posted December 29, 2009 (edited) I am an idiot bogQ, you are completely right. I mixed up two things from the help:The flag parameter can be a combination of the following values:decimal flag 0Button-relatedOK button AndButton PressedOKReturn value1Jos, your proposal works like a charm.I apologize for wasting the time of all of those who took the time to answer this message. I will try to be more careful in the future. I was so sure that "0" was the right value that I completely missed that (I am a beginner but it is not at all my first Msgbox). Edited December 29, 2009 by Akshay07 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