paul1149 Posted September 14, 2009 Share Posted September 14, 2009 Hi, Brand new here but an old AutoIt lover. I'm finishing a script which formats Wordpress posts for publication. The last step is to provide a means of escape for if I realize I'm not yet ready to run the script. Is there any way to enable the Cancel button to actually do something, without going the longhand GUI route? Currently I'm simply writing MsgBox(flag, "title", "text") Secondly, it would help a lot if I could drag and drop text to an input box, but the ones I specify are impervious to doing so. Thanks much. I see the old yahoo group has gone to seed, so I appreciate this forum. bb, Paul Behold, I will allure her, I will lead her into the wilderness and speak tenderly to her - Ho. 2.14 Link to comment Share on other sites More sharing options...
muhmuuh Posted September 14, 2009 Share Posted September 14, 2009 (edited) Welcome to the forums Msgbox returns the ID of the button pressed You can do $pressed=Msgbox(1, "Dilema", "OK or Cancel - the choice is yours") if $pressed==2 Then Msgbox(0, "yey", 'yey you pressed "Cancel"') It is written in the helpfile... Edited September 14, 2009 by muhmuuh I ran. I ran until my muscles burned and my veins pumped battery acid. Then I ran some more. Link to comment Share on other sites More sharing options...
paul1149 Posted September 14, 2009 Author Share Posted September 14, 2009 Welcome to the forums Msgbox returns the ID of the button pressed You can do $pressed=Msgbox(1, "Dilema", "OK or Cancel - the choice is yours") if $pressed==2 Then Msgbox(0, "yey", 'yey you pressed "Cancel"') It is written in the helpfile... Thanks for the welcome, and the answer. I did look in Help but came up empty. I'll put this to use and get back on it. Thanks much, Paul Behold, I will allure her, I will lead her into the wilderness and speak tenderly to her - Ho. 2.14 Link to comment Share on other sites More sharing options...
jvanegmond Posted September 14, 2009 Share Posted September 14, 2009 I know you said you'd rather not take the GUI approach, but here's a GUI anyway. Next poster will probably have a super easy way to make inputbox accept drag and drop. 8) expandcollapse popup#include <GUIConstantsEx.au3> $input = _InputBox("Drag and drop example", "Try drag and drop!") If Not @error Then MsgBox(4096, "drag drop file", $input ) EndIf Func _InputBox($sTitle, $sPrompt) Local $file, $btnOk, $btnCancel, $msg, $ret GUICreate($sTitle, 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES GUICtrlCreateLabel($sPrompt, 10, 10) $file = GUICtrlCreateInput("", 10, 50, 300, 21) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $btnOk = GUICtrlCreateButton("Ok", 100, 80, 100, 25) $btnCancel = GUICtrlCreateButton("Cancel", 210, 80, 100, 25) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Return SetError(1,0,0) Case $msg = $btnOk ExitLoop Case $msg = $btnCancel Return SetError(1,0,0) EndSelect WEnd $ret = GUICtrlRead($file) If ($ret == "") Then Return SetError(1,0,0) Else Return $ret EndIf EndFunc github.com/jvanegmond Link to comment Share on other sites More sharing options...
paul1149 Posted September 14, 2009 Author Share Posted September 14, 2009 Welcome to the forums Msgbox returns the ID of the button pressed You can do $pressed=Msgbox(1, "Dilema", "OK or Cancel - the choice is yours") if $pressed==2 Then Msgbox(0, "yey", 'yey you pressed "Cancel"') It is written in the helpfile... muhmuuh, I have half success. On the msgboxes, this is working: $pressed = MsgBox( 305, "Press'ENTER' to cancel!", "Paras to be blockquoted must have 'xxx ' prepended. ", 3) if $pressed==2 Then Exit But on the inputboxes, this doesn't work: $URL = InputBox ("Add Social Media Linkbar", "Enter post's URL:", "", "", 400, 100, 0, 400) if $URL==1 Then Exit Help says 1 is the error code for the cancel button, whereas 0 is a successful return. But obviously I'm missing a connection of some kind. Thanks, Paul Behold, I will allure her, I will lead her into the wilderness and speak tenderly to her - Ho. 2.14 Link to comment Share on other sites More sharing options...
jvanegmond Posted September 14, 2009 Share Posted September 14, 2009 You get the last error code with the @error macro. $URL = InputBox ("Add Social Media Linkbar", "Enter post's URL:", "", "", 400, 100, 0, 400) If @error == 1 Then Exit github.com/jvanegmond Link to comment Share on other sites More sharing options...
paul1149 Posted September 14, 2009 Author Share Posted September 14, 2009 I know you said you'd rather not take the GUI approach, but here's a GUI anyway. Next poster will probably have a super easy way to make inputbox accept drag and drop. 8) expandcollapse popup#include <GUIConstantsEx.au3> $input = _InputBox("Drag and drop example", "Try drag and drop!") If Not @error Then MsgBox(4096, "drag drop file", $input ) EndIf Func _InputBox($sTitle, $sPrompt) Local $file, $btnOk, $btnCancel, $msg, $ret GUICreate($sTitle, 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES GUICtrlCreateLabel($sPrompt, 10, 10) $file = GUICtrlCreateInput("", 10, 50, 300, 21) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $btnOk = GUICtrlCreateButton("Ok", 100, 80, 100, 25) $btnCancel = GUICtrlCreateButton("Cancel", 210, 80, 100, 25) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Return SetError(1,0,0) Case $msg = $btnOk ExitLoop Case $msg = $btnCancel Return SetError(1,0,0) EndSelect WEnd $ret = GUICtrlRead($file) If ($ret == "") Then Return SetError(1,0,0) Else Return $ret EndIf EndFunc Thanks, manadar. Looks like good clean code, and I'm going to hold onto it for future reference. Thanks! Paul Behold, I will allure her, I will lead her into the wilderness and speak tenderly to her - Ho. 2.14 Link to comment Share on other sites More sharing options...
paul1149 Posted September 14, 2009 Author Share Posted September 14, 2009 You get the last error code with the @error macro.$URL = InputBox ("Add Social Media Linkbar", "Enter post's URL:", "", "", 400, 100, 0, 400)If @error == 1 Then ExitPerfect. I'm not sure why an error spec is needed for the inputbox but not for the msgbox, but obviously that's the case!I also don't know why there's a lack of d&d support for these boxes. Probably a Windows issue, I'm suspect.Thanks guys for your great help. I'm up and running!Paul Behold, I will allure her, I will lead her into the wilderness and speak tenderly to her - Ho. 2.14 Link to comment Share on other sites More sharing options...
jvanegmond Posted September 14, 2009 Share Posted September 14, 2009 Perfect. I'm not sure why an error spec is needed for the inputbox but not for the msgbox, but obviously that's the case! That's a simple question to answer. Consider the following: $URL = InputBox ("Add Social Media Linkbar", "Enter post's URL:", "", "", 400, 100, 0, 400) if $URL==1 Then Exit If I enter the number 1 into the InputBox, the application would exit because it thinks I pressed cancel. It's probably the same with MsgBox. (Haven't checked.) In other functions where @error really isn't needed it is used for consistency. In fact, AutoIt does not need @error at all. InputBox could just return an array with 2 dimensions. The first dimension would contain the error flag, and the second one the result string (or "" in case of error.) Same with other functions. github.com/jvanegmond Link to comment Share on other sites More sharing options...
paul1149 Posted September 14, 2009 Author Share Posted September 14, 2009 That's a simple question to answer. Consider the following: $URL = InputBox ("Add Social Media Linkbar", "Enter post's URL:", "", "", 400, 100, 0, 400) if $URL==1 Then Exit If I enter the number 1 into the InputBox, the application would exit because it thinks I pressed cancel. It's probably the same with MsgBox. (Haven't checked.) In other functions where @error really isn't needed it is used for consistency. In fact, AutoIt does not need @error at all. InputBox could just return an array with 2 dimensions. The first dimension would contain the error flag, and the second one the result string (or "" in case of error.) Same with other functions. Yes, that example makes sense. The rest of it I'm not totally up to, but get your drift. Thanks again, Paul Behold, I will allure her, I will lead her into the wilderness and speak tenderly to her - Ho. 2.14 Link to comment Share on other sites More sharing options...
jvanegmond Posted September 14, 2009 Share Posted September 14, 2009 Don't worry, Paul. Good luck with your coding! Greetings, Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
TurionAltec Posted September 14, 2009 Share Posted September 14, 2009 In fact, AutoIt does not need @error at all. InputBox could just return an array with 2 dimensions. The first dimension would contain the error flag, and the second one the result string (or "" in case of error.) Same with other functions.It may not need it, but then it becomes a pain because then you need to deal with arrays when you want to do something with the input from InputBox. And for a quick script for personal use, it may be allowable to not deal with error handling. Link to comment Share on other sites More sharing options...
jvanegmond Posted September 14, 2009 Share Posted September 14, 2009 github.com/jvanegmond Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 14, 2009 Share Posted September 14, 2009 (edited) Too much six-pack abs... more like: Edited September 14, 2009 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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