5 Replies Latest reply on Nov 4, 2013 7:32 AM by jwshelton22

# Greatest value of 3 variables

### Title

Greatest value of 3 variables

### Post

I am writing a script where I have created 3 variables, each contains the length of a field's contents.

How can I sort the variables by descending?

I need to determine which variable has the highest number.

thanks,

Jim

• ###### 1. Re: Greatest value of 3 variables

The easiest way to sort values in a database is to use the database engine's sort capability. Put each value in a different related record and display them in a portal. The portal or the portal's underlying relationship can specify a sort order that lists the largest value first.

• ###### 2. Re: Greatest value of 3 variables

Is there not a way to sort the three variables as they are each a number within the script?

• ###### 3. Re: Greatest value of 3 variables

Inside a script, you must program your own SORT.  Use a series of IF's

Example:

If A>B    flip them using a temporary variable.

TheN

If B>C  flip…. etc.

Jim…

• ###### 4. Re: Greatest value of 3 variables

For exactly three values:

Let ( [ First = Max ( \$Var1 ; \$Var2 ; \$Var3 ) ;
Last = Min ( \$Var1 ; \$Var2 ; \$Var3 ) ;
Mid = case ( First = \$Var1 ; Max ( \$Var2 ; \$Var3 ) ;
First = \$Var2 ; Max ( \$Var1 ; \$Var3 ) ;
Max ( \$Var1 ; \$Var3 )
)
] ;
List ( First ; Mid ; Last )
) // let

• ###### 5. Re: Greatest value of 3 variables

thanks,

as it will always be three values

jim