Revised code:
function calcDiffMaxMin(fieldNames) {
var values = [];
for (var i in fieldNames) {
var v = this.getField(fieldNames[i]).valueAsString;
if (v!="") values.push(+v);
}
if (values.length==0) event.value = "";
else {
values.sort(function(a, b){return a-b});
var maxValue = values[values.length-1];
var minValue = values[0];
var diffMaxMin = maxValue - minValue;
event.value = diffMaxMin;
}
}
You can place this code as a doc-level script and then call it from your field like so:
calcDiffMaxMin(["A", "B", "C", "D"]);
.
Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com