Evaluating Statements Prior to the OK Button


The dynamically updating dialog box example, enable1.pan has an issue because the checkbox state is not preserved when the function option changes. For example, set the checkbox state to unchecked, select Gnormal and then re-select Grandom, the checkbox state reverts to unchecked. This is because the checkbox state is set to the variable nodc. Although Gnormal and Grandom options re-evaluate the entire dialog box, nodc is not assigned a new value until the OK button is processed.




The % modifier causes an evaluation area expression to evaluate immediately after it has been changed.


// enable2.pan - enable/disable control



// initialize parameters

{defvar("gfunc", "Grandom");defvar("nodc", 1)}


// checkbox enabled

{setvar("chkbox", gfunc=="Grandom")}


Generate Noise

Generate Function <# r w=20>~gfunc = "<{gfunc}>"~<Grandom><Gnormal>

Remove DC Offset  <% c e={chkbox}>~nodc=<{nodc}>~<0><1>



~genfunc = sprintf("%s(100, 1/100)", gfunc)

~if(nodc && chkbox, setwf(sprintf("demean(%s)", genfunc)), setwf(genfunc))



Because nodc is set immediately when changed, the checkbox state is now preserved when the Gnormal or Grandom option is selected.