Keep getting TypeError: RngTable[UpperWt] is undefined
I need help trying to solve / fix the above error.
I understand why/where the error is occurring, I just can't figure out how to properly resolve it.
When I enter a value between 10000 and 18000 in the Weight field ( AW variable ), this works, however, when I enter 18001, I get the above error.- Suggestions?
Thanks in advance!
var AW = this.getField("Weight").value;
var b = Math.ceil(AW / 1000) * 1000;
var c = Math.floor(AW/ 1000) * 1000;
var d = 10000;
var e = 18300;
var UpperWt = b;
if (b > e) {
UpperWt.value = e;
} else {
UpperWt.value = b;
}
var LowerWt = c;
if (c < d) {
LowerWt.value = d;
} else {
LowerWt.value = c;
}
var t = this.getField("Temperature").value;
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;
console.println("Hello World1");
var f = Math.round(((((RngTable[UpperWt][nTEMP]) - (RngTable[UpperWt][nTEMP-1])) / 11) * (t - 27)) + (1 * RngTable[UpperWt][nTEMP-1]));
console.println("Hello World2");
var g = Math.round(((((RngTable[LowerWt][nTEMP]) - (RngTable[LowerWt][nTEMP-1])) / 11) * (t - 27)) + (1 * RngTable[LowerWt][nTEMP-1]));
console.println("Hello World3");
if (AW >= LowerWt && AW <= UpperWt) {
this.getField("UWt_Dist").value = Math.round(((((RngTable[UpperWt][nTEMP]) - (RngTable[UpperWt][nTEMP-1])) / 11) * (t - 27)) + (1 * RngTable[UpperWt][nTEMP-1]));
console.println("Hello World4");
this.getField("LWt_Dist").value = Math.round(((((RngTable[LowerWt][nTEMP]) - (RngTable[LowerWt][nTEMP-1])) / 11) * (t - 27)) + (1 * RngTable[LowerWt][nTEMP-1]));
console.println("Hello World5");
this.getField("CWt_Dist").value = ((((f - g) / (UpperWt-LowerWt)) * (AW - LowerWt)) + (g));
}
