Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5338 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi all

I have a script that is setting 27 numeric variables. I then need to find the highest value - which I can do with the Max calculation. But I also need get the text name of the variable that contained the highest value.

The only way I currently know to do this would be to build a Case statement that has 27 lines with each doing something like this:

$V1 > $V2 and $V1 > $V3 and $V1 > $V4 ; "$V1" ;

$V2 > $V1 and $V2 > $V3 and $V2 > $V4 ; "$V2" ;

$V3 > $V1 and $V3 > $V2 and $V3 > $V4 ; "$V3" ;

This would be a massive 27x27 grid. I know there must be an easier function for this (like Max) that would return the field name instead of the value, but for the life of me I can't find it.

Any and all help gladly and humbly accepted.

Roger

Posted

good question.

My first choice is to see the two variables battle to the death in a centrally located container field, but, I'm thinking that might be a bit much even for FM.

My variables are currently named $M001 thru $M027. Based on the away things are setup, the higher numbered variables should be the priority over the lower numbered variables.

thanks

Posted

Well, you could find the position of the maximum value in:

List ( $M001 ; $M002 ; $M023 ; ... ; $M027 )

or in a list of the opposite order, if you prefer. See here for something similar:

http://www.briandunning.com/cf/908

I am not sure overall that's the best way to approach whatever you're trying to do here, though.

Posted (edited)

If all of the values are integers, you can encode the number used in the field name in the decimal portion of the value.

Where you would previously do this...

Set Variable [$M001; Value:244]

Set Variable [$M004; Value:18425]

Set Variable [$M018; Value:4879]

Your flow would go like this.

Set Variable [$M001; Value:244.001]

Set Variable [$M004; Value:18425.004]

Set Variable [$M018; Value:4879.018]

Set Variable [$M027; Value:555.027]

Find the maximum value.

Pull out the decimal part and use that to know the variable name.

It may be easier if you use repetitions in $M instead of $M001 through $M027 so that you can access the value using the number as a repetition index programatically.

You may notice that this technique will choose the higher numbered variable's value when determining the maximum in a tie.

Edited by Guest
comment about handling ties
Posted

Tominator, that's sneaky — I like it! And yes, my numbers are integers.

I have never used repetitions, nor do I understand them, so I will do a bit of reading. If there are any quick tips you have on how they work or good samples to look at I'd appreciate the extra help. That said, even if I do not use repetitions, i can see how I can solve this issue using your initial decimal trick.

again, thanks

Posted (edited)

I have never used repetitions, nor do I understand them, so I will do a bit of reading. If there are any quick tips you have on how they work or good samples to look at I'd appreciate the extra help.

If you are already using the script step Set Variable[], then using a repetition is very easy.

In the Specify... dialog for Set Variable[] you will find three items: Name, Value, and Repetition.

Instead of choosing a unique name for each of your 27 variables, use the same one and type in a unique number in the Repetition box. Think of them as subscripts to the name in exactly the same way you are already writing out the numbers in the name itself.

The beauty here is that you can specify the repetition number using a calculation. It could be the counting index in a loop for example. Thus you could assign a different variable repetition in each iteration of your loop.

When accessing the values of a variable with repetitions, you could either use the GetRepetition() function or use the variable name with [] after it.

In a calculation expression, where you previously would have used

$M001 + $M024 + $M027

if you set up $M with repetitions 1 through 27, you can use

$M[1] + $M[24] + $M[27]

Edited by Guest
Posted

OK, getting my head around that. After playing with it a short bit I have one question to make sure I am getting this right.

When I set the first repetition of $M (previously $M001), then I would set the Repetition value to 1.

When I set the second repetition of $M (previously $M002), then I would set the Repetition value to 2.

However, when I set the first script to 1, the listing of the script step omits the [1] from the variable name. Does this mean that $M is also the same as $M[1]?

Posted

However, when I set the first script to 1, the listing of the script step omits the [1] from the variable name. Does this mean that $M is also the same as $M[1]?

Yes. When you write $M, it is equivalent to $M[1]. The first repetition is assumed when it is unspecified.

Posted

Set Var $max; 27

Set Var $K; 1

Set var $max_key; ""

Loop

Exit loop if $k > $max

if $m[$k] > $m[0]

Set var $m[0]; $m[$k]

Ser var $max_key; $k

end if

set var $k; 1+ $k

End Loop

Posted

BruceR, your loop and Tominator's repetition & decimal trick will work wonderfully together. Many thanks.Have been rebuilding another part of my logic utilizing the repetitions to make it easier for the rest of the build.

This thought process does not come easily some days so moving slowly and testing often.

Thanks for all your help.

This topic is 5338 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.