Rather than placing a returned series in the current window, allowing the user to specify the destination window offers greater flexibility. The _dwinstr system macro provides a easy way to add a destination window drop-down list to any dialog in a consistent manner.
// deswin1.pan - destination window
@dialog
// adjust width and height
@adjust_width 1
@adjust_height 1
// default values
{defvar("dist", 0);defvar("len", 100);defvar("dx", 0.01)}
Generate Random Data
Distribution <r n>~dist = <{dist}>~<Uniform><Normal>
Length: <w=20>~len = <{len}>~input(2)
Delta X: <w=20>~dx = <{dx}>~input(1)
<L>
{_dwinstr}
<L>
~menuclear
~if(dist==0, gfunc = "Grandom", gfunc = "Gnormal")
~eval(sprintf("%s := %s(%d, %g)", _dwin, gfunc, len, dx))
The _dwinstr macro expands to automatically include a selectable list of currently available target windows. The _dwin system macro contains the selected window as a string. Invoking the menu with the _menuf system macros automatically initializes _dwin to the current window:
_menuf("deswin1.pan")
The _dwinstrS system macro accepts modifier strings. For example, to set the width of the destination window control to 20, the same width as the previous controls:
// deswin2.pan - destination window
@dialog
// adjust width and height
@adjust_width 1
@adjust_height 1
// default values
{defvar("dist", 0);defvar("len", 100);defvar("dx", 0.01)}
Generate Random Data
Distribution <r n>~dist = <{dist}>~<Uniform><Normal>
Length: <w=20>~len = <{len}>~input(2)
Delta X: <w=20>~dx = <{dx}>~input(1)
<L>
{_dwinstrS("w=20")}
<L>
~menuclear
~if(dist==0, gfunc = "Grandom", gfunc = "Gnormal")
~eval(sprintf("%s := %s(%d, %g)", _dwin, gfunc, len, dx))
The _verifydwin and _checkdwin system macros automatically prompt the user if the destination window contains data that might get overwritten.
// deswin3.pan - destination window
@dialog
// adjust width and height
@adjust_width 1
@adjust_height 1
// default values
{defvar("dist", 0);defvar("len", 100);defvar("dx", 0.01)}
Generate Random Data
Distribution <r n>~dist = <{dist}>~<Uniform><Normal>
Length: <w=20>~len = <{len}>~input(2)
Delta X: <w=20>~dx = <{dx}>~input(1)
<L>
{_dwinstrS("w=20")}
<L>
~if(dist==0, gfunc = "Grandom", gfunc = "Gnormal")
~_verifydlen
~if (_checkdwin, eval(sprintf("%s := %s(%d, %g)", _dwin, gfunc, len, dx)))
Selecting Yes places the series in W3, selecting No re-displays the original dialog box to give the user an opportunity to change the destination and Cancel cancels both dialog boxes. The _menuclear statement is no longer required.