Not sure if this has been discussed before - or if I’m storing up trouble for the future (I’ve always been a saver ) but this combining of if() and the dialog is much more readable that the format suggested in the sample code.
Where I need to ask the user a question with a dialog I’ve been using this:
var thePressedButton = plugins.dialogs.showQuestionDialog('Warning', 'This SQL has NOT been applied to the Database yet - do you want to continue without applying it ?','OK', 'Cancel');
if(thePressedButton =='OK'){
//Get the current record index or do some work etc.
} }
else {return;}
A technique I used in VB seems to work well here too:
if('OK' == plugins.dialogs.showQuestionDialog('Warning', 'Lets see which button you press ?','OK', 'Cancel')){ //do some work}
else {return;}
Doesn’t save a lot of code but is more readable IMHO.
That is indeed more efficient with one exception.
When you use more buttons than OK/Cancel then you need to put the result in a variable (or use a switch statement).
That is indeed more efficient with one exception.
When you use more buttons than OK/Cancel then you need to put the result in a variable (or use a switch statement).
As a general rule, I think you also improve readability considerably by reversing your condition, and doing the following:
if('OK' != plugins.dialogs.showQuestionDialog('Warning', 'Lets see which button you press ?','OK', 'Cancel'))
return;
//do some work
You are really testing for a reason to exit, so the resulting action should logically be to trigger the return. Also, you save a level of indentation on your actual working code.
agiletortoise:
As a general rule, I think you also improve readability considerably by reversing your condition, and doing the following:
if('OK' != plugins.dialogs.showQuestionDialog('Warning', 'Lets see which button you press ?','OK', 'Cancel'))
return;
//do some work
You are really testing for a reason to exit, so the resulting action should logically be to trigger the return. Also, you save a level of indentation on your actual working code.
g.
Your absolutely right Greg - I use both directions results dependant.