Combine if() with plugins.dilaog...

Not sure if this has been discussed before - or if I’m storing up trouble for the future (I’ve always been a saver :wink: ) 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.

Hi Ian,

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).

ROCLASI:
Hi Ian,

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).

Aha - thanks Robert.

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.

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.