akappycanfieldtack.com Posted June 20, 2011 Posted June 20, 2011 I have four fields and a graphic that depends on how many of the four fields have data (not empty). The following code always returns "EL_BC_1Lines.pdf" regardless. I don't seem to be adding the variables correctly. Perhaps there is a better way overall? I have a client pressing for a result! if(Field("Phone1")!="") var P1=1 if(Field("Phone2")!="") var P2=1 if(Field("Phone3")!="") var P3=1 if(Field("Phone4")!="") var P4=1 var PT=P1+P2+P3+P4 if (PT=1) return Resource("EL_BC_1Lines.pdf"); if (PT=2) return Resource("EL_BC_2Lines.pdf"); if (PT=3) return Resource("EL_BC_3Lines.pdf"); if (PT=4) return Resource("EL_BC_4Lines.pdf");
Dan Korn Posted June 20, 2011 Posted June 20, 2011 I would do this: function CountNonEmptyFields() { var count = 0; for (var i = 0; i < arguments.length; i++) { if (Field(arguments[i])) count++; } return count; } var count = CountNonEmptyFields("Phone1", "Phone2", "Phone3", "Phone4"); return Resource("EL_BC_" + count + "Lines.pdf");
akappycanfieldtack.com Posted June 20, 2011 Author Posted June 20, 2011 Dan, Thanks for the timely response, and as I hoped, the code is elegant. Much appreciated, Andy
Recommended Posts
Archived
This topic is now archived and is closed to further replies.