4 Replies Latest reply on Sep 22, 2016 5:57 AM by discrhythmia

    Keep getting TypeError: RngTable[UpperWt] is undefined

    discrhythmia Level 1

      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));

      }

        • 1. Re: Keep getting TypeError: RngTable[UpperWt] is undefined
          George_Johnson MVP & Adobe Community Professional

          I haven't looked through the entire script, but this bit of code:

           

          var UpperWt = b;

          if (b > e) {

          UpperWt.value = e;

          } else {

          UpperWt.value = b;

          }

           

          needs to be changed to this:

           

          var UpperWt = b;

          if (b > e) {

          UpperWt = e;

          } else {

          UpperWt = b;

          }

           

          Do the same type of correction to the next block as well.

          • 2. Re: Keep getting TypeError: RngTable[UpperWt] is undefined
            George_Johnson MVP & Adobe Community Professional

            And it can be simplified to:

             

            var UpperWt = b;

            if (b > e) {

                UpperWt = e;

            }

            • 3. Re: Keep getting TypeError: RngTable[UpperWt] is undefined
              Test Screen Name Most Valuable Participant

              Once you've made those changes please repost the script AND the complete console log.

              • 4. Re: Keep getting TypeError: RngTable[UpperWt] is undefined
                discrhythmia Level 1

                That worked like a charm!

                Thanks!

                 

                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 = e;

                }

                 

                var LowerWt = c;

                if (c < d) {

                LowerWt = d;

                }

                 

                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));

                }Hello World1

                Hello World2

                Hello World3

                Hello World4

                Hello World5