Copy link to clipboard
Copied
I've renamed my Array and keep getting this error. When I run script with the renamed Array in the console, it calculates appropriately. I've tried going through line by line and can't seem to find the error. Might be I just need a fresh set of eyes to catch my mistake. As per usual, everyones help & advice is greatly appreciated.
(original script)
var AW = this.getField("Weight").value;
var t = this.getField("Temperature").value;
var b = Math.ceil(AW / 1000) * 1000;
var c = Math.floor(AW / 1000) * 1000;
var d = 10000;
var e = 18300;
var m = 1;
var UpperWt = b;
if (b > e) {
UpperWt = e;
}
var LowerWt = c;
if (c < d) {
LowerWt = d;
}
var RngTable = new Array();
RngTable[18300] = ["4686","4857","5029","5201","5942","7370"];
RngTable[18000] = ["4530","4695","4860","5025","5732","7088"];
RngTable[17000] = ["4010","4152","4295","4437","5031","6149"];
RngTable[16000] = ["3550","3675","3800","3925","4412","5285"];
RngTable[15000] = ["3127","3229","3330","3431","3857","4663"];
RngTable[14000] = ["2744","2841","2938","3035","3412","4090"];
RngTable[13000] = ["2382","2461","2540","2619","2925","3475"];
RngTable[12000] = ["2242","2314","2385","2456","2727","3203"];
RngTable[11000] = ["2160","2227","2295","2362","2592","2958"];
RngTable[10000] = ["2085","2152","2220","2287","2493","2787"];
var nWT = this.getField("Weight").value;
var nTEMP = 5;
var f = Math.round(RngTable[UpperWt][nTEMP]);
var g = Math.round(RngTable[LowerWt][nTEMP]);
if (t >= (-18) && t < (-7)) {
var f = Math.round(((((RngTable[UpperWt][nTEMP-4]) - (RngTable[UpperWt][nTEMP-5])) / 11) * (t + 18)) + (1 * RngTable[UpperWt][nTEMP-5]));
var g = Math.round(((((RngTable[LowerWt][nTEMP-4]) - (RngTable[LowerWt][nTEMP-5])) / 11) * (t + 18)) + (1 * RngTable[LowerWt][nTEMP-5]));
} else if (t >= (-7) && t < 0) {
var f = Math.round(((((RngTable[UpperWt][nTEMP-3]) - (RngTable[UpperWt][nTEMP-4])) / 11) * (t + 7)) + (1 * RngTable[UpperWt][nTEMP-4]));
var g = Math.round(((((RngTable[LowerWt][nTEMP-3]) - (RngTable[LowerWt][nTEMP-4])) / 11) * (t + 7)) + (1 * RngTable[LowerWt][nTEMP-4]));
} else if (t >= 0 && t < 4) {
var f = Math.round(((((RngTable[UpperWt][nTEMP-3]) - (RngTable[UpperWt][nTEMP-4])) / 11) * (t - 4)) + (1 * RngTable[UpperWt][nTEMP-3]));
var g = Math.round(((((RngTable[LowerWt][nTEMP-3]) - (RngTable[LowerWt][nTEMP-4])) / 11) * (t - 4)) + (1 * RngTable[LowerWt][nTEMP-3]));
} else if (t >= 4 && t < 16) {
var f = Math.round(((((RngTable[UpperWt][nTEMP-2]) - (RngTable[UpperWt][nTEMP-3])) / 11) * (t - 4)) + (1 * RngTable[UpperWt][nTEMP-3]));
var g = Math.round(((((RngTable[LowerWt][nTEMP-2]) - (RngTable[LowerWt][nTEMP-3])) / 11) * (t - 4)) + (1 * RngTable[LowerWt][nTEMP-3]));
} else if (t >= 16 && t < 27) {
var f = Math.round(((((RngTable[UpperWt][nTEMP-1]) - (RngTable[UpperWt][nTEMP-1])) / 11) * (t - 16)) + (1 * RngTable[UpperWt][nTEMP-2]));
var g = Math.round(((((RngTable[LowerWt][nTEMP-1]) - (RngTable[LowerWt][nTEMP-1])) / 11) * (t - 16)) + (1 * RngTable[LowerWt][nTEMP-2]));
} else if (t >= 27 && t < 38) {
var f = Math.round(((((RngTable[UpperWt][nTEMP]) - (RngTable[UpperWt][nTEMP-1])) / 11) * (t - 27)) + (1 * RngTable[UpperWt][nTEMP-1]));
var g = Math.round(((((RngTable[LowerWt][nTEMP]) - (RngTable[LowerWt][nTEMP-1])) / 11) * (t - 27)) + (1 * RngTable[LowerWt][nTEMP-1]));
}
var h = (UpperWt-LowerWt);
if (h == 0) {
h = m;
}
if (AW >= LowerWt && AW <= UpperWt) {
this.getField("CWt_Dist").value = ((((f - g) / (h)) * (AW - LowerWt)) + (g));
}
If AW = 17500 & t = 16, this calculates correctly to 4731
(Script with renamed array)
var AW = this.getField("Weight").value;
var t = this.getField("Temperature").value;
var b = Math.ceil(AW / 1000) * 1000;
var c = Math.floor(AW / 1000) * 1000;
var d = 10000;
var e = 18300;
var m = 1;
var UpperWt = b;
if (b > e) {
UpperWt = e;
}
var LowerWt = c;
if (c < d) {
LowerWt = d;
}
var DistTable = new Array();
DistTable[18300] = ["4686","4857","5029","5201","5942","7370"];
DistTable[18000] = ["4530","4695","4860","5025","5732","7088"];
DistTable[17000] = ["4010","4152","4295","4437","5031","6149"];
DistTable[16000] = ["3550","3675","3800","3925","4412","5285"];
DistTable[15000] = ["3127","3229","3330","3431","3857","4663"];
DistTable[14000] = ["2744","2841","2938","3035","3412","4090"];
DistTable[13000] = ["2382","2461","2540","2619","2925","3475"];
DistTable[12000] = ["2242","2314","2385","2456","2727","3203"];
DistTable[11000] = ["2160","2227","2295","2362","2592","2958"];
DistTable[10000] = ["2085","2152","2220","2287","2493","2787"];
var nWT = this.getField("Weight").value;
var nTEMP = 5;
var f = Math.round(DistTable[UpperWt][nTEMP]);
var g = Math.round(DistTable[LowerWt][nTEMP]);
if (t >= (-18) && t < (-7)) {
var f = Math.round(((((DistTable[UpperWt][nTEMP-4]) - (DistTable[UpperWt][nTEMP-5])) / 11) * (t + 18)) + (1 * DistTable[UpperWt][nTEMP-5]));
var g = Math.round(((((DistTable[LowerWt][nTEMP-4]) - (DistTable[LowerWt][nTEMP-5])) / 11) * (t + 18)) + (1 * DistTable[LowerWt][nTEMP-5]));
} else if (t >= (-7) && t < 0) {
var f = Math.round(((((DistTable[UpperWt][nTEMP-3]) - (DistTable[UpperWt][nTEMP-4])) / 11) * (t + 7)) + (1 * DistTable[UpperWt][nTEMP-4]));
var g = Math.round(((((DistTable[LowerWt][nTEMP-3]) - (DistTable[LowerWt][nTEMP-4])) / 11) * (t + 7)) + (1 * DistTable[LowerWt][nTEMP-4]));
} else if (t >= 0 && t < 4) {
var f = Math.round(((((DistTable[UpperWt][nTEMP-3]) - (DistTable[UpperWt][nTEMP-4])) / 11) * (t - 4)) + (1 * DistTable[UpperWt][nTEMP-3]));
var g = Math.round(((((DistTable[LowerWt][nTEMP-3]) - (DistTable[LowerWt][nTEMP-4])) / 11) * (t - 4)) + (1 * DistTable[LowerWt][nTEMP-3]));
} else if (t >= 4 && t < 16) {
var f = Math.round(((((DistTable[UpperWt][nTEMP-2]) - (DistTable[UpperWt][nTEMP-3])) / 11) * (t - 4)) + (1 * DistTable[UpperWt][nTEMP-3]));
var g = Math.round(((((DistTable[LowerWt][nTEMP-2]) - (DistTable[LowerWt][nTEMP-3])) / 11) * (t - 4)) + (1 * DistTable[LowerWt][nTEMP-3]));
} else if (t >= 16 && t < 27) {
var f = Math.round(((((DistTable[UpperWt][nTEMP-1]) - (DistTable[UpperWt][nTEMP-1])) / 11) * (t - 16)) + (1 * DistTable[UpperWt][nTEMP-2]));
var g = Math.round(((((DistTable[LowerWt][nTEMP-1]) - (DistTable[LowerWt][nTEMP-1])) / 11) * (t - 16)) + (1 * DistTable[LowerWt][nTEMP-2]));
} else if (t >= 27 && t < 38) {
var f = Math.round(((((DistTable[UpperWt][nTEMP]) - (DistTable[UpperWt][nTEMP-1])) / 11) * (t - 27)) + (1 * DistTable[UpperWt][nTEMP-1]));
var g = Math.round(((((DistTable[LowerWt][nTEMP]) - (DistTable[LowerWt][nTEMP-1])) / 11) * (t - 27)) + (1 * DistTable[LowerWt][nTEMP-1]));
}
var h = (UpperWt-LowerWt);
if (h == 0) {
h = m;
}
if (AW >= LowerWt && AW <= UpperWt) {
this.getField("CWt_Dist").value = ((((f - g) / (h)) * (AW - LowerWt)) + (g));
}
SyntaxError: missing ) in parenthetical
46: at line 47
Copy link to clipboard
Copied
I'm not getting any syntax errors for either code. Are you sure that's the exact code you're using?
By the way, there's no need to put parentheses around numbers, like in this statement:
t >= (-18)
It could simply be:
t >= -18
Copy link to clipboard
Copied
Copied the code above, made the change in your reply. Still getting a syntax error when I paste the code into my form's button javascript action. Code still works and calculates correctly when I paste it directly into the javascript console, highlight the entire code and press Shift-Enter on my Mac (correctly calculates value of 4731 with a "Weight" value of 17500 and "Temperature" value of 16, when entered on my form.
var AW = this.getField("Weight").value;
var t = this.getField("Temperature").value;
var b = Math.ceil(AW / 1000) * 1000;
var c = Math.floor(AW / 1000) * 1000;
var d = 10000;
var e = 18300;
var m = 1;
var UpperWt = b;
if (b > e) {
UpperWt = e;
}
var LowerWt = c;
if (c < d) {
LowerWt = d;
}
var DistTable = new Array();
DistTable[18300] = ["4686","4857","5029","5201","5942","7370"];
DistTable[18000] = ["4530","4695","4860","5025","5732","7088"];
DistTable[17000] = ["4010","4152","4295","4437","5031","6149"];
DistTable[16000] = ["3550","3675","3800","3925","4412","5285"];
DistTable[15000] = ["3127","3229","3330","3431","3857","4663"];
DistTable[14000] = ["2744","2841","2938","3035","3412","4090"];
DistTable[13000] = ["2382","2461","2540","2619","2925","3475"];
DistTable[12000] = ["2242","2314","2385","2456","2727","3203"];
DistTable[11000] = ["2160","2227","2295","2362","2592","2958"];
DistTable[10000] = ["2085","2152","2220","2287","2493","2787"];
var nWT = this.getField("Weight").value;
var nTEMP = 5;
var f = Math.round(DistTable[UpperWt][nTEMP]);
var g = Math.round(DistTable[LowerWt][nTEMP]);
if (t >= -18 && t < -7) {
var f = Math.round(((((DistTable[UpperWt][nTEMP-4]) - (DistTable[UpperWt][nTEMP-5])) / 11) * (t + 18)) + (1 * DistTable[UpperWt][nTEMP-5]));
var g = Math.round(((((DistTable[LowerWt][nTEMP-4]) - (DistTable[LowerWt][nTEMP-5])) / 11) * (t + 18)) + (1 * DistTable[LowerWt][nTEMP-5]));
} else if (t >= -7 && t < 0) {
var f = Math.round(((((DistTable[UpperWt][nTEMP-3]) - (DistTable[UpperWt][nTEMP-4])) / 11) * (t + 7)) + (1 * DistTable[UpperWt][nTEMP-4]));
var g = Math.round(((((DistTable[LowerWt][nTEMP-3]) - (DistTable[LowerWt][nTEMP-4])) / 11) * (t + 7)) + (1 * DistTable[LowerWt][nTEMP-4]));
} else if (t >= 0 && t < 4) {
var f = Math.round(((((DistTable[UpperWt][nTEMP-3]) - (DistTable[UpperWt][nTEMP-4])) / 11) * (t - 4)) + (1 * DistTable[UpperWt][nTEMP-3]));
var g = Math.round(((((DistTable[LowerWt][nTEMP-3]) - (DistTable[LowerWt][nTEMP-4])) / 11) * (t - 4)) + (1 * DistTable[LowerWt][nTEMP-3]));
} else if (t >= 4 && t < 16) {
var f = Math.round(((((DistTable[UpperWt][nTEMP-2]) - (DistTable[UpperWt][nTEMP-3])) / 11) * (t - 4)) + (1 * DistTable[UpperWt][nTEMP-3]));
var g = Math.round(((((DistTable[LowerWt][nTEMP-2]) - (DistTable[LowerWt][nTEMP-3])) / 11) * (t - 4)) + (1 * DistTable[LowerWt][nTEMP-3]));
} else if (t >= 16 && t < 27) {
var f = Math.round(((((DistTable[UpperWt][nTEMP-1]) - (DistTable[UpperWt][nTEMP-1])) / 11) * (t - 16)) + (1 * DistTable[UpperWt][nTEMP-2]));
var g = Math.round(((((DistTable[LowerWt][nTEMP-1]) - (DistTable[LowerWt][nTEMP-1])) / 11) * (t - 16)) + (1 * DistTable[LowerWt][nTEMP-2]));
} else if (t >= 27 && t < 38) {
var f = Math.round(((((DistTable[UpperWt][nTEMP]) - (DistTable[UpperWt][nTEMP-1])) / 11) * (t - 27)) + (1 * DistTable[UpperWt][nTEMP-1]));
var g = Math.round(((((DistTable[LowerWt][nTEMP]) - (DistTable[LowerWt][nTEMP-1])) / 11) * (t - 27)) + (1 * DistTable[LowerWt][nTEMP-1]));
}
var h = (UpperWt-LowerWt);
if (h == 0) {
h = m;
}
if (AW >= LowerWt && AW <= UpperWt) {
this.getField("CWt_Dist").value = ((((f - g) / (h)) * (AW - LowerWt)) + (g));
}
Copy link to clipboard
Copied
Works fine for me...
Copy link to clipboard
Copied
I'm using Pro X, would that have anything to do with it?
Copy link to clipboard
Copied
I doubt it. I'm using XI Pro.
What application are you using to edit the code?
Copy link to clipboard
Copied
Directly in javascript window & console in acrobat.
If I'm having issues, that I can't resolve with minor troubleshooting, I copy the code into Brackets and use that.
Copy link to clipboard
Copied
Use an external JavaScript editor.
Copy link to clipboard
Copied
Thank you Bernd,
I'm starting to look for one. What external editors would you recommend?
Copy link to clipboard
Copied
On MS Windows I use notepad++.
Copy link to clipboard
Copied
I upgraded to the new version of Acrobat Pro, and my original script ended up working ... I use Mac, so I'll stick with Brackets. Also found this which I found worked well for me - Online Javascript Editor and Compiler at Codepad – Remoteinterview.io
Copy link to clipboard
Copied
After trying my script in a few different editors with it working - I decided to upgrade to latest/greatest Acrobat Pro ... low and behold ... the script worked ... thanks for your help and patience.
On another note, I had asked you a separate question in a different post regarding calling different arrays- and my question was a bit confusing. Incorporating the script above, I want to have a few more arrays with the same structure. What would be the best way to incorporate into the script above?
Example- If I had a form field and I entered a value of 1, it would use the above DistTable array. If I entered a value of 2, it would use a second array (DistTable2) in the script above, a value of 3; DistTable3 etc.
var DistTable2 = new Array();
DistTable2[18300] = ["4859","5036","5216","5544","6526","0"];
DistTable2[18000] = ["4697","4866","5036","5354","6287","8200"];
DistTable2[17000] = ["4154","4301","4447","4719","5488","7000"];
DistTable2[16000] = ["3676","3805","3934","4168","4769","5913"];
DistTable2[15000] = ["3230","3334","3438","3632","4187","5150"];
DistTable2[14000] = ["2842","2942","3042","3223","3689","4428"];
DistTable2[13000] = ["2462","2543","2624","2772","3150","3750"];
DistTable2[12000] = ["2314","2388","2461","2594","2922","3463"];
DistTable2[11000] = ["2228","2298","2367","2490","2742","3173"];
DistTable2[10000] = ["2153","2223","2292","2412","2613","2938"];
Or, is there a better way incorporating everything into a single array?
Copy link to clipboard
Copied
You can create an array of these arrays...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now