ResNullius Posted September 14, 2007 Posted September 14, 2007 I was digging through some old scraps of Foxpro code and found a snippet that I used to use all the time. The idea isn't by any means original with me, but I did a quick search of the forums, didn't find anything quite like it, and thought others might find it useful.The code should be self explanatory, but basically it allows you to write simple Yes/No msgboxes and receive back a true/false response.The only required parameter is the text to display as a prompt. You can specify a title, but if you don't, it will use the script name minus the extension. I know the syntax is not the same as the standard msgbox (the title comes after the text instead of the other way around), but it makes it really easy to write a quick If _Confirm("Are you sure you want to do that") then ... kind of thing. Small sample included.If _Confirm("Continue the process?") Then ;put affirmative Stuff here MsgBox(0, "YES", "Smart Choice") Else ;put Non-affirmative Stuff here MsgBox(0, "NO", "OK, your loss!") EndIf Func _Confirm($sText, $sTitle = @ScriptName) If Not IsDeclared("IDYES") Then Dim $IDYES = 6 If Not IsDeclared("MB_ICONQUESTION") Then Dim $MB_ICONQUESTION = 32 If Not IsDeclared("MB_YESNO") Then Dim $MB_YESNO = 4 If $sTitle = @ScriptName Then $sTitle = StringTrimRight($sTitle, StringLen($sTitle) - StringInStr($sTitle, ".", -1) + 1) $lResponse = MsgBox($MB_ICONQUESTION + $MB_YESNO, $sTitle, $sText) Return $lResponse = $IDYES EndFunc ;==>_ConfirmPretty bad when the preamble is longer than the code, huh?
BillLuvsU Posted September 14, 2007 Posted September 14, 2007 Definatly a time saver, good idea. If I could count the number of times I've written out the whole yes/no process >_>. Anyways goodjob! [center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw
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