1 2 Previous Next 18 Replies Latest reply on Jan 17, 2016 7:20 PM by sokol@rogers.com

# search variables for lowest value

how would I search 8 variables (example:  var1=6, var2=9, var3=1 ... ) and return the variable name (here would be var3) if it has the lowest value ... ?

• ###### 1. Re: search variables for lowest value

Min ( var1 ; var2 ; var3 )

Chris Cain

Extensitech

• ###### 2. Re: search variables for lowest value

But the OP wanted to return the variable name not just the smallest value

This might work:

Let ([

var1=6; var2=2; var3=11;

smallest = Min ( var1 ; var2 ; var3 )

];

Case ( smallest = var1; "var1"; smallest = var2; "var2"; smallest = var3; "var3"; "error" )

)

A recursive custom function may be more extensible.

• ###### 3. Re: search variables for lowest value

was hoping for something a little more slick and generic as the variable values do change ...

• ###### 4. Re: search variables for lowest value

His answer is generic for any values, values are embeded in the calculation only for testing (and you wrote variable names without \$ and \$\$, so usable only in Let() function itself).

Do you want generic for variable names, or count of variables?

What do you want if two or more variables have same lowest value?

And, don't you get the values from records?

• ###### 5. Re: search variables for lowest value

And if two variables have the same lowest value?

What are you really trying to accomplish here? What do these variables represent in real world terms? How are they created and what is the data in them? Why do you want to know the lowest value?

There is likely another way to accomplish what you want.

• ###### 6. Re: search variables for lowest value

The numbers are the length of 8 lines of text.   I want to add more text to the shortest line.

• ###### 7. Re: search variables for lowest value

Agreed. This is an example where people are trying to help but there is not a lot of information to go on. You will likely get better answers if you explain what you are trying to achieve rather than pre-empting what the best solution might be.

So, sokol, what are you trying to do?

For example, if you have eight lines of text in a field separated by return characters, you can probably find out where to insert the text without the variables you first mentioned.

There are some smart people here who will likely provide a 'slick and generic' answer when they know what you are doing

• ###### 8. Re: search variables for lowest value

Let's see if I can explain my self better!   I have 8 distinct variables for many records:

ap1

ap2

...

ap8

that contain text from 50 to 100 characters long forming a block of information to be read.    Occasionally I need to add more text and I would like to automatically add it to the shortest of the 8 lines.    Is that explanation making my issue clearer?    Thanks!!!!!

• ###### 9. Re: search variables for lowest value

I feel more hard to get you.

"Each records" have 8 distinct "values" in a field, or 8 values are in 8 fields?

"variable" need to be defined each time when file open (\$\$), script run (\$), calculate (Let(var=val;)) etc., so your "information" may be stored in field, not variable.

• ###### 10. Re: search variables for lowest value

let me try another approach as my terminology was not correct.  Each record has 8 FIELDS.  These are separate and the layout has each of them on a separate row to make reading the record easier.  At times I need to add more text to one of the fields ... and I would like to add it automatically to the one that has the fewest characters:ap1ap2ap3ap4ap5ap6ap7ap8sorry for the confusion and misusing variable ... it should have been FIELDS.

• ###### 11. Re: search variables for lowest value

Let's step back another step.

If the fields are interchangeable and it never matters WHERE you put this data; what is this data anyway?

What is the purpose of this database solution?

• ###### 12. Re: search variables for lowest value

this data is discussion with a client.   it is regarding many things we have chatted about.    Each line (field AP1 ... AP8) starts with an activity and then a description (for example:   Runninggo on treadmill for 30 minutes daily) ... after 8 topics are discussed, sometimes there is a 9th one ... so I  would like to add that topic (for example:  Meatonce weekly)  to the shortest topic already discussed to make sure there is room on the line and it looks nicely spaced.

• ###### 13. Re: search variables for lowest value

The best way to do this is to use a separate table with a record for each discussion rather than fields. You can have any number of discussions that way, 8 or 9 or 20.

• ###### 14. Re: search variables for lowest value

Sorry I'm stuck with the eight fields stacked on top of each other, for every record.    When all eight records have text in them, at times I have to add a bit more text to the shortest field.

1 2 Previous Next