At times, it is not convenient to explicitly list all possible options when the menu is created. An application may call for a different group of options depending upon the situation or type of worksheet. In these cases, the list box options can be stored as a list in a variable, macro or as a list within a file. For example, define the following variable:
mylistvar = strlist("cos","sin","normal","random");
The variable mylistvar contains a list of strings separated by newlines. To use the list in a menu, place an asterisk * between the angle braces in the display area, and place mylistvar in the input area. When used with a list of values, the * modifier encloses each string in the list with angle braces < > and treats the result as a list of options. For example:
// listbox1.pan
@panel
// initialize input values
{defvar("wlen", 100);defvar("wspc", 0.01)}
List Box Options
Generate Waveform: <* w=20>~wf="< >"~mylistvar
Length: <w=20>~wlen=<{wlen}>~input(2)
Spacing: <w=20>~wspc=<{wspc}>~input(1)
<L>
~menuclear
~setwf(sprintf("G%s(%d, %g)",wf, wlen, wspc))
When this dialog box is invoked, a list box is presented for the choice of waveforms.
Now, redefine mylistvar as follows:
mylistvar = strlist("sqrt","sqr");
and invoke the dialog box with:
menufile("listbox1.pan")
The list of options has changed without changing the menu file itself.
Options for drop down list boxes can also be saved in a text file as a list of strings separated by newlines. Simply place an equal sign = modifier in the display area of the menu file between the angle braces < >. For example, redefine mylistvar as follows:
mylistvar = strfile("mychoice.txt");
Next, create a text file, mychoice.txt, with these choices:
sin
cos
sqr
sqrt
normal
random
With listbox1.pan as a template, replace the asterisk * modifier with an equal sign = as below:
// listbox2.pan
@panel
// initialize input values
{defvar("wlen", 100);defvar("wspc", 0.01)}
List Box Options
Generate Waveform: <= w=20>~wf="< >"~mylistvar
Length: <w=20>~wlen=<{wlen}>~input(2)
Spacing: <w=20>~wspc=<{wspc}>~input(1)
<L>
~menuclear
~setwf(sprintf("G%s(%d, %g)",wf, wlen, wspc))
Now the list of choices are automatically obtained from a file.