Calculation that ignores fields with non-numbers.
New to Java, basic question:
7 fields (Sun, Mon, Tue, Wed, Thu, Fri, Sat) plus a Total Field.
I want the Total Field to:
1. calculate the sum of each field that is a number (0.1 to 12.0);
2. not include in the calculation fields that have letters (i.e. "Sun", "Mon", etc);
Note: the default values of each of the 7 fields is (ie. "Sun", "Mon", etc.)
My script breaks when the value of the fields is a non-number:
var Sun = this.getField("Sun 1");
var Mon = this.getField("Mon 1");
var Tue = this.getField("Tue 1");
var Wed = this.getField("Wed 1");
var Thu = this.getField("Thu 1");
var Fri = this.getField("Fri 1");
var Sat = this.getField("Sat 1");
var totalField = this.getField("Total Field");
var schedTotal = Number(Sun.valueAsString) + Number(Mon.valueAsString) + Number(Tue.valueAsString) + Number(Wed.valueAsString) + Number(Thu.valueAsString) + Number(Fri.valueAsString) + Number(Sat.valueAsString);
if(schedTotal > 0 && schedTotal < 37.6) {
totalField.value = schedTotal;
totalField.textColor = color.black;
Sun.strokeColor = color.transparent;
Mon.strokeColor = color.transparent;
Tue.strokeColor = color.transparent;
Wed.strokeColor = color.transparent;
Thu.strokeColor = color.transparent;
Fri.strokeColor = color.transparent;
Sat.strokeColor = color.transparent; }
else totalField.event.value = "Total";
totalField.textColour = color.ltGray;
Sun.strokeColor = color.red;
Mon.strokeColor = color.red;
Tue.strokeColor = color.red;
Wed.strokeColor = color.red;
Thu.strokeColor = color.red;
Fri.strokeColor = color.red;
Sat.strokeColor = color.red;