Closing custom dialog box causing run-time error

I've created a custom dialog box with multiple inputs for the user to enter information.  It works fine if the user actually runs the script which exports an HTML file.  However, if you close the window with either the 'Close" button or the Windows X button, I get an run-time error instead of simply closing the dialog.  I currently have no code associated with the Close button, but it seems to try to run the last line of code of my main function.  How would I determine if the user hit the Close button so as to skip over this last line.

Here is the main code:

void exportBaselineComparison(){
    Module currMod = null
    
    currMod = current Module;
    
    if (null currMod){
        infoBox("This utility can only be run from a formal module." );
        return;
    }
    
    buildDialog(currMod);
    
    writeFileEnd(out);
}
exportBaselineComparison();

Of course, the buildDialog does exactly what it says and gives the "Run" button its action.  I'm almost positive that when I hit either close button, the function tries to continue with the last line (writeFileEnd), but because out is null, it gives me the run-time error.  So what I really want to do is create an if-statement that says if buildDialog ran, then call writeFileEnd.  Is there an easier way to do this than setting another Boolean variable within the buildDialog function?

 

Chris


chrscote - Tue Mar 07 13:13:35 EST 2017

Re: Closing custom dialog box causing run-time error
strathglass - Tue Mar 07 14:01:28 EST 2017

Presumably you have a "block()" call on the dialog that gets put up by buildDialog()

You should add an explicit routine to process the close/cancel request, with a global (lets say "noExport"). 

So assuming your DB for the GUI is called dbConfig, then you could try something like this:

 

bool doExport=true //by default, we assume user will not cancel export
...
void closeAction(DB dbConfig)
{
    doExport=false
    hide dbConfig
    release(dbConfig)
}
...
void buildDialog(Module m)
{
    ...
    close(dbConfig,true,closeAction) //add this line where you add other DBEs
    ...
}
    ...
    buildDialog(currMod)
    writeFileEnd(out) //not sure what this does, does it need to be qualified so its only done when you want to export??
}
if (doExport)
{
    exportBaselineComparison(); //you have to qualify this function to only run if doExport is true
}