3 Replies Latest reply on Aug 8, 2016 4:19 AM by TomHays

# Min Function with a local variable

I have a script that collects a series of numbers in a local variable (I'll call it \$n).  There is a looping process so I gather the numbers in a horizontal list.  The end result looks like this:

40;12;17.1428571428571429

That list is created in a variable \$nList via a calculation:

If (

not Isempty ( \$nList ) ;

\$nList & ";" GetResults ( "n" ) ;

GetResults ( "n" )

)

The GetResults ( "" ) is a custom function from Six Fried Rice for passing key;value parameters.  In the Data Viewer, \$nList is defined as 40;12;17.1428571428571429, as expected.

I want to get the lowest number in the list so I then create a new variable, \$nListLowest:

Min ( \$nList )

However, it evaluates as a question mark (?).

I modified the \$nList calculation to make sure the passed variables are numbers:

If (

not Isempty ( \$nList ) ;

\$nList & ";" GetAsNumber ( GetResults ( "n" ) ) ;

GetAsNumber ( GetResults ( "n" ) )

)

But that produced the same result.

In the Data Viewer, I can copy the result of \$nList and make a new Watch expression:

Min ( 40;12;17.1428571428571429 )

That returns 12, as expected.

I suspect the \$nList variable is a string and cannot be evaluated by the Min () function.

Any thoughts?

• ###### 1. Re: Min Function with a local variable

You need Evaluate() as

Evaluate ( "Min(" & \$nList & ")" )

1 of 1 people found this helpful
• ###### 2. Re: Min Function with a local variable

Thanks.

• ###### 3. Re: Min Function with a local variable

An alternative to using Min() on the completed list is to locate the lowest value as you are looping to build the list.

Using looping structure, assign the \$nListLowest to the first value in the list.

As you loop over new values, assign the new value to be \$nListLowest if it is lower than the current value of \$nListLowest.

In this, make sure to use GetAsNumber(\$nValue) < GetAsNumber(\$nListLowest) so that you avoid comparing the number values as strings.

-Tom