ant2ne Posted February 3, 2009 Share Posted February 3, 2009 MsgBox(4,"Shutting Down", "This computer will do something in a 10 seconds. Press NO to cancel",10)How do I determine if OK or CANCEL is pressed? F1 reference didn't help much. Link to comment Share on other sites More sharing options...
KaFu Posted February 3, 2009 Share Posted February 3, 2009 Read MsgBox() in the helpfile... While MsgBox(4, "Shutting Down", "This computer will do something in a 10 seconds. Press NO to cancel", 10) <> 7 Sleep(10) WEnd Skysnake 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
ant2ne Posted February 3, 2009 Author Share Posted February 3, 2009 Read MsgBox() in the helpfile... While MsgBox(4, "Shutting Down", "This computer will do something in a 10 seconds. Press NO to cancel", 10) <> 7 Sleep(10) WEndI don't think you understand my question. How do I determine if cancel or ok was pressed. Like, if OK is pressed then X =0 if CANCEL is pressed then X = 1 Link to comment Share on other sites More sharing options...
sandin Posted February 3, 2009 Share Posted February 3, 2009 $return_value = MsgBox(4,"Shutting Down", "This computer will do something in a 10 seconds. Press NO to cancel",10) Switch $return_value case 1 ;OK ---> Flags: 0, 1 MsgBox(0, "Return Value", "OK") case 2 ;cancel ---> Flags: 1, 3, 5, 6 MsgBox(0, "Return Value", "Cancel") case 3 ;abort ---> Flags: 2 MsgBox(0, "Return Value", "Abort") case 4 ;retry ---> Flags: 2, 5 MsgBox(0, "Return Value", "Retry") case 5 ;Ignore ---> Flags: 2 MsgBox(0, "Return Value", "Ignore") case 6 ;Yes ---> Flags: 3, 4 MsgBox(0, "Return Value", "Yes") case 7 ;No ---> Flags: 3, 4 MsgBox(0, "Return Value", "No") case 10 ;Try Again ---> Flags: 6 MsgBox(0, "Return Value", "Try again") case 11 ;Continue ---> Flags: 6 MsgBox(0, "Return Value", "Continue") EndSwitch oskrki 1 Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll Link to comment Share on other sites More sharing options...
KaFu Posted February 3, 2009 Share Posted February 3, 2009 First... RTFM... you invoke the msgbox with flag=4, meaning 'Yes and No' and no 'OK and Cancel', which would be flag=1... then as you can see in my code, the loop ends when the msgbox() returns 7, which means 'No'. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
BJJ Posted February 3, 2009 Share Posted February 3, 2009 look in helpfile Link to comment Share on other sites More sharing options...
ant2ne Posted February 3, 2009 Author Share Posted February 3, 2009 First... RTFM... you invoke the msgbox with flag=4, meaning 'Yes and No' and no 'OK and Cancel', which would be flag=1... then as you can see in my code, the loop ends when the msgbox() returns 7, which means 'No'. Cancel or OK the example would have been enough. The manual I got doesn't say anything about "<> 7" or "while" and "wend". I highlight the word msgbox and press F1 to view the help file. If you have a better manual, please let me know where I can get it. I don't want it to loop waiting for a reply. I never said I wanted it to loop waiting for a reply. I nfact when the ,10) second limit of the msgbox statment is reached, I want the code to continue. Otherwise I wouldn't have put it in there. What I'm looking for is something more like what sandin posted. But that wasn't in my help file either. If I knew WHAT I was looking for, I could have found it. I always feel that the purpose of these forums is to learn about the things that you didn't even know you didn't know. select word MsgBox and press F1. I can see where it says "Button Pressed Return Value" but it doesn't say how to use those. Please forgive my ignorance as I try to learn. MsgBox -------------------------------------------------------------------------------- Displays a simple message box with optional timeout. MsgBox ( flag, "title", "text" [, timeout [, hwnd]] ) Parameters flag The flag indicates the type of message box and the possible button combinations. See remarks. title The title of the message box. text The text of the message box. timeout [optional] Timeout in seconds. After the timeout has elapsed the message box will be automatically closed. The default is 0, which is no timeout. hwnd [optional] The window handle to use as the parent for this dialog. Return Value Success: Returns the ID of the button pressed. Failure: Returns -1 if the message box timed out. Button Pressed Return Value OK 1 CANCEL 2 ABORT 3 RETRY 4 IGNORE 5 YES 6 NO 7 TRY AGAIN ** 10 CONTINUE ** 11 Remarks The flag parameter can be a combination of the following values: decimal flag Button-related Result hexadecimal flag 0 OK button 0x0 1 OK and Cancel 0x1 2 Abort, Retry, and Ignore 0x2 3 Yes, No, and Cancel 0x3 4 Yes and No 0x4 5 Retry and Cancel 0x5 6 ** Cancel, Try Again, Continue 0x6 decimal flag Icon-related Result hexadecimal flag 0 (No icon) 0x0 16 Stop-sign icon 0x10 32 Question-mark icon 0x20 48 Exclamation-point icon 0x30 64 Information-sign icon consisting of an 'i' in a circle 0x40 decimal flag Default-related Result hexadecimal flag 0 First button is default button 0x0 256 Second button is default button 0x100 512 Third button is default button 0x200 decimal flag Modality-related Result hexadecimal flag 0 Application 0x0 4096 System modal (dialog has an icon) 0x1000 8192 Task modal 0x2000 decimal flag Miscellaneous-related Result hexadecimal flag 0 (nothing else special) 0x0 262144 MsgBox has top-most attribute set 0x40000 524288 title and text are right-justified 0x80000 ** Only valid on Windows 2000/XP and above. For example, to specify a SYSTEMMODAL box with the YES/NO buttons the flag value would be 4096+4 (or 4100) If using hexadecimal flags, that would be 0x1000+0x4 (or 0x1004). A message box appears centered on screen and resizes according to the text it contains. However, the title could get truncated if the SYSTEMMODAL flag (4096) is used.. If "title" is equal to Default keyword @Scriptname is used Related InputBox, ToolTip, TrayTip, SplashTextOn Example MsgBox(4096, "Test", "This box will time out in 10 seconds", 10) Link to comment Share on other sites More sharing options...
KaFu Posted February 3, 2009 Share Posted February 3, 2009 (edited) akn, sorry for my rudeness ... if you want it this way, try: if MsgBox(266513,"Shutting Down", "This computer will shut down in a 10 seconds...." & @crlf & @crlf & "Press CANCEL to abort the shutdown.",10) = 2 Then ; do not Shutdown MsgBox(0,'','Cancel pressed') Else ; Shutdown MsgBox(0,'','Ok pressed or msgbox timed out...') EndIf Edited February 3, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2009 Moderators Share Posted February 3, 2009 (edited) ant2ne, Set a variable to the return value of the message box. Then you can use the variable as you wish (I have used a Switch...Case in this example):$answer = MsgBox(32 + 4, "Query", "Are you sure?") Switch $answer Case 6; Yes ExitLoop Case 7; No Return EndSwitch The possible value of the variable depends on the buttons you have chosen to use in the initial parameter of the MsgBox function. M23 Edited February 3, 2009 by Melba23 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...
ant2ne Posted February 3, 2009 Author Share Posted February 3, 2009 ant2ne, Set a variable to the return value of the message box. Then you can use the variable as you wish (I have used a Switch...Case in this example):$answer = MsgBox(32 + 4, "Query", "Are you sure?") Switch $answer Case 6; Yes ExitLoop Case 7; No Return EndSwitch The possible value of the variable depends on the buttons you have chosen to use in the initial parameter of the MsgBox function. M23I see that in sadin's reply. I never knew that was how one captures return values. But now I do. Very interesting and I plan to use it a lot in the future. THANKS 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