These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Comparing values

Koen_Wyckmans
Registered: Feb 9 2009
Posts: 18

Hi,

I want to compasre several values in Acrobatfields, so the form automaticly generates the highest number.

How do I tackle this problem?

tanks

My Product Information:
Acrobat Pro Extended 9.1, Macintosh
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You can use JavaScirpts' 'Math.max()' function to get the maximum value of 2 numbers.

You will have to write a control loop compare each pair of values to get the maximum value. A couple of functions will provide enough flexibility to compute the maximum value from an array of field names or values.

Document level functions to determine maximum value from an array of values or field names:
function Max(fX, fY) {// return maximum value of 2 valuesreturn Math.max(fX, fY);} // end max function function MaxArrayV(aValues) {// return max value from an array of valuesvar fMax = aValues[0]; // establish base value// loop through array of values for(i = 0; i < aValues.length; i++) {// on process non null fields and only numbersif(aValues[i] != '' & !isNaN(aValues[i]) ) {fMax = Max(fMax, aValues[i]);} // end not null} // end loopreturn fMax;} // end MaxArray function ValueArrayFN(aFieldNames) {// return array of values from list of field names// define array for valuesvar aValues = new Array(aFieldNames.length);// populate the arrayfor(i = 0; i < aFieldNames.length; i++) {aValues[i] = this.getField(aFieldNames[i]).value;}return aValues} // end ValueArrayFN function

Custom calculation script for field names:
// array of field names to compare valuesvar aNames = new Array( "Text1.0", "Text1.1","Text1.2", "Text1.3" );event.value = MaxArrayV(ValueArrayFN(aNames)); // orevent.value = MaxArrayV(ValueArrayFN([ "Text1.0", "Text1.1", "Text1.2", "Text1.3"]) );

George Kaiser