PickValid

Description: Attempts to return a valid value given a list of parameters.
Returns: Varies
Usage: Script or steady state.
Function Groups: Logic Control
Related to: Valid
Format: PickValid(Parm1, Parm2 [, Parm3, ...])
Parameters:  
Parm1, Parm2, Parm3...
Required. Any number of parameters giving any expressions, from which the first valid value will be selected.
Comments: This function continues its search through its parameter list in order until the first valid value is found. If no valid parameters are supplied, INVALID is returned.

Examples:

a = Invalid;
b = 83;
c = Invalid;
d = -1;
validAns1 = PickValid(a, b, c, d);
validAns2 = PickValid(a, c, d, b);

The value of validAns1 and validAns2 will be 83 and -1 respectively. A typical use for this function is in setting default values as follows:

<
MyGraphic
(
  parmLeft;
)
[
  Left       { local value for the left edge };
]
SetDefaults
[
  IF 1 Main;
  [
    left = PickValid(parmLeft, 100);
  ]
]
Main...
>

Given that module MyGraphic draws something in the window, adding the PickValid statement ensures that even if an invalid value is given as a parameter, the box will still be displayed, because its invalid parameter will have been replaced with the default value of 100.

 

Note that a local parameter is defined for Left, rather than using the parameter, parmLeft. This is necessary because, if the value passed to the module's parameter had been defined as a constant Invalid, it would not be possible to redefine it within MyGraphic using PickValid or any other statement.