Detecting when a user clicks Cancel in the GETNUMBER (and other) dialog(s).As you probably discovered, when a user presses the Cancel button in a GETNUMBER dialog box, Origin generates a #Command Error! which will stop your script. If you need to continue processing and want to know which button in the dialog was pressed you can make use of the following general technique.
Use NOTEPAD or another text editor to create a file called UTIL.OGS. Copy the following text to your text editor and save the file.
// Beginning of sample code
[getnumber]
flag=0;
var=%2;
getnumber (%1) var (%3);
flag=1;
return;
// End of sample code
Note that a variable named flag is set to 0 before the getnumber command and set to 1 after the getnumber command. When this code is called via a run.section command, the two lines after the getnumber command will execute only if the user clicks the OK button. Since this code is executing in an external file, the #Command Error! that is generated by pressing Cancel stops the external script from completing, but allows the script that called it to continue. Your calling script can then check the value of the flag variable to determine what action the user took:
•flag = 1 indicates the user clicked OK •flag = 0 indicates the user clicked Cancel
Here is an example of how to call and use the above routine:
sample = 10;
run.section(util,getnumber,"My Variable" sample "Enter your value");
if(flag==1)
{
sample = var;
type -a You clicked OK or pressed Enter and the value of sample is now $(sample);
} else {
type -a You clicked Cancel. Value of sample will not be changed.;
}
This same technique can be applied with other 'GET...' dialogs also.