Setting Default Values in Dialog Boxes

 

A dialog box can specify default values for input fields.  A default value can be fixed or variable and is displayed when the dialog box is invoked.  Add fixed default input values to the dialog box simply by specifying the desired defaults inside the expression area. The following dialog box provides fixed default values for Length and Spacing:

 

 

// mkwave4.pan

// Fixed Default Values

@dialog

 

Generate Noise

 

Length:  <w=20>~wlen=<100>~input(2)

Spacing: <w=20>~wspc=<0.01>~input(1)

<L>

~menuclear;GRANDOM(wlen,wspc)

 

 

 

 

The fixed default values now appear in the menu when it is invoked.

 

To make a dialog box "remember" previous input values, use the curly braces {} around the variable or macro name. The following dialog box displays the current values of the input variables as the default inputs:

 

// mkwave5.pan

// Variable Default Values

@dialog

 

Generate Noise

 

Length:  <w=20>~wlen=<{wlen}>~input(2)

Spacing: <w=20>~wspc=<{wspc}>~input(1)

<L>

~menuclear;GRANDOM(wlen,wspc)

 

Notice the braces {} around the variable names.  The braces evaluate and display the current values of wlen and wspc when the dialog box is invoked. Each time a new value is entered, the value is assigned to the corresponding variable. Because the dialog box uses the variable as the default value, the last value entered becomes the newly displayed default value.

 

DEFVAR assigns a value to a variable only if the variable does not exist. When used in a dialog box, DEFVAR automatically initializes a variable to a specified value if it was not previously initialized. The variable effectively assigns the last entered value as the new default.

 

// mkwave6.pan

// Variable Default Values

@dialog

 

// initialize input values

{defvar("wlen", 100);defvar("wspc", 0.01)}

 

Generate Noise

 

Length:  <w=20>~wlen=<{wlen}>~input(2)

Spacing: <w=20>~wspc=<{wspc}>~input(1)

<L>

~menuclear;GRANDOM(wlen,wspc)

 

When the dialog box is first invoked, the Length field defaults to 100 and Spacing defaults to 0.01. The fields display the last entered values thereafter.

 

Specifying a default value is one method for creating a dialog box that reports a set of desired values. For example:

 

// report1.pan - display values

@dialog

 

Series Metrics

 

Mean:  <w=40>~<{mean}>~

Min:   <w=40>~<{min}>~

Max:   <w=40>~<{max}>~

Range: <w=40>~<{max-min}>~

Stdev: <w=40>~<{stdev}>~

<L>

 

 

Because the input area expressions are not set, the dialog box simply displays the desired values.

 

By default, the first control in a dialog box has focus. We can remove the focus highlight of the first field by explicitly setting the focus to the OK button.

 

// report2.pan - display values

@dialog

 

// focus on OK button

@focus 1

 

Series Metrics

 

Mean:  <w=40>~<{mean}>~

Min:   <w=40>~<{min}>~

Max:   <w=40>~<{max}>~

Range: <w=40>~<{max-min}>~

Stdev: <w=40>~<{stdev}>~

<L>

 

 

 

Moving the focus results in a cleaner display. A value 1 for @focus specifies the OK button, 2 specifies the Cancel button and 4 specifies the Help button, if any.