Using a loop to compare LOTS of pairs of field values
Hello all, I really hope someone can help me with this issue. (I'm not a hugely well-educated javascripter, so please feel free to assume zero knowledge in your responses...)
(I'm running Acrobat DC)
I have a form that contains a LOT of fields. the form is called "front.pdf". The fields are arranged on it in 32 rows of sixty fields (I know: that's a LOT!). Each field is named as follows:
A.01, A.02, A.03, A.04 ... up to ... A.59, A.60
B.01, B.02, B.04 ... => ... B.59, B.60
The rows go up to Z, then AA, BB up to GG. (All rows go from 1–60)
There is another pdf form, called "back.pdf" that is attached (as an attachment) to the first. It contains the same amount of fields, named exactly the same way, the only difference on this one is that the rows run from 60 down to 1 rather than from 1 up to 60.
Each cell, on both forms, will have a value that is either empty: ("",) or the lowercase letter Z: ("z").
I'm trying to write a script that, when attached onMouseUp to a button on the parent pdf (front.pdf), will loop through all of the cells on front.pdf, and compare the value of the cell with the value of a cell on back.pdf, and if they are both the same, set the value of the cell on front.pdf to "j".
The pairs to compare need to be as follows:
Front Cell Back Cell
A.01 A.60
A.02 A.59
A.03 A.58
...and so on, so that when the number on front.pdf INCREASES, the number on back.pdf DECREASES, although the Row letter stays the same.
So far, I have come up with the following (please don't scoff: I'm new and trying ever so hard, lol):
(I have a document level script that opens the attached back.pdf, and puts it into a var called ("vBack".)
for (var i = 0 ; i < this.numFields-4 ; i++) {
var f = this.getField(this.getNthFieldName(i));
var fString = String(f);
var fStringArr = fString.split('.');
var fLett = fStringArr[0];
var fNum = fStringArr[1];
var bNum;
if (fNum.value == 01){
bNum.value = 60;}
if (fNum.value == 02){
bNum.value = 59;}
if (fNum.value == 03){
bNum.value = 58;}
if (fNum.value == 04){
bNum.value = 57;}
if (fNum.value == 05){
bNum.value = 56;}
if (fNum.value == 06){
bNum.value = 55;}
if (fNum.value == 07){
bNum.value = 54;}
if (fNum.value == 08){
bNum.value = 53;}
if (fNum.value == 09){
bNum.value = 52;}
if (fNum.value == 10){
bNum.value = 51;}
if (fNum.value == 11){
bNum.value = 50;}
if (fNum.value == 01){
bNum.value = 49;}
if (fNum.value == 01){
bNum.value = 48;}
if (fNum.value == 01){
bNum.value = 47;}
if (fNum.value == 01){
bNum.value = 46;}
if (fNum.value == 01){
bNum.value = 45;}
if (fNum.value == 01){
bNum.value = 44;}
if (fNum.value == 01){
bNum.value = 43;}
if (fNum.value == 01){
bNum.value = 42;}
if (fNum.value == 01){
bNum.value = 41;}
if (fNum.value == 01){
bNum.value = 40;}
if (fNum.value == 01){
bNum.value = 39;}
if (fNum.value == 01){
bNum.value = 38;}
if (fNum.value == 01){
bNum.value = 37;}
if (fNum.value == 01){
bNum.value = 36;}
if (fNum.value == 01){
bNum.value = 35;}
if (fNum.value == 01){
bNum.value = 34;}
if (fNum.value == 01){
bNum.value = 33;}
if (fNum.value == 01){
bNum.value = 32;}
if (fNum.value == 01){
bNum.value = 31;}
if (fNum.value == 01){
bNum.value = 30;}
if (fNum.value == 01){
bNum.value = 29;}
if (fNum.value == 01){
bNum.value = 28;}
if (fNum.value == 01){
bNum.value = 27;}
if (fNum.value == 01){
bNum.value = 26;}
if (fNum.value == 01){
bNum.value = 25;}
if (fNum.value == 01){
bNum.value = 24;}
if (fNum.value == 01){
bNum.value = 23;}
if (fNum.value == 01){
bNum.value = 22;}
if (fNum.value == 01){
bNum.value = 21;}
if (fNum.value == 01){
bNum.value = 20;}
if (fNum.value == 01){
bNum.value = 19;}
if (fNum.value == 01){
bNum.value = 18;}
if (fNum.value == 01){
bNum.value = 17;}
if (fNum.value == 01){
bNum.value = 16;}
if (fNum.value == 01){
bNum.value = 15;}
if (fNum.value == 01){
bNum.value = 14;}
if (fNum.value == 01){
bNum.value = 13;}
if (fNum.value == 01){
bNum.value = 12;}
if (fNum.value == 01){
bNum.value = 11;}
if (fNum.value == 01){
bNum.value = 10;}
if (fNum.value == 01){
bNum.value = 09;}
if (fNum.value == 01){
bNum.value = 08;}
if (fNum.value == 01){
bNum.value = 07;}
if (fNum.value == 01){
bNum.value = 06;}
if (fNum.value == 01){
bNum.value = 05;}
if (fNum.value== 01){
bNum.value = 04;}
if (fNum.value == 01){
bNum.value = 03;}
if (fNum.value == 01){
bNum.value = 02;}
if (fNum.value == 01){
bNum.value = 01;}
var fComp = fLett + "." + fNum;
var bComp = fLett + "." + bNum;
var b = fLett + "." + bNum;
if (this.getField(fComp).value == vBack.getField(bComp).value){
f.value = "j";
f.textColor = color.gray;
}
}
It's not working, and I'm at a loss.
If anyone can advise on what I need to do to tidy this up, or can point me in the direction of knowing WHY this is a bad way to do it, and that there might be a much better, simpler, cleaner way, I'm all ears, and will be incredibly grateful. Obsequiously so, in all probability...
Many thanks in advance for your willingness to share your time and your knowledge to help a beginner. It really IS appreciated.
NathanG
