4 Replies Latest reply: May 15, 2013 10:33 AM by Ken van Mulder RSS

    Nesting variables in the script

    Ken van Mulder

      Hello,

       

      I'm having difficulty getting nested variables and parameters working correctly in the load script.

       

      Here is the script that I'm using:

       

      TestData:

      LOAD * Inline

      [

                Key, Value

                ABC, 1

                DEF, 2

                GHI, 2

                JKL, 3

      ];

       

      set vTestFor1 = (Value=1);

      set vTestFor2 = (Value=2);

      set vTestFor3 = (Value=3);

       

      set vCalcFor2=if($(vTestFor2), 'Y', 'N');

      set vCalcForXScript=if($(vTestFor$1), 'Y', 'N');

       

      vCalcForXScript doesn't work - it translates the inner variable at load time. If I set the same value within the Variable Overview, it does work, though.

       

      I've attached an example that shows the problem. vCalcForXOverView has been set in the Variable Overview and the chart shows it is working.

       

      How do I get the same effect, but by setting vCalcForXScript in the script?

       

      Thanks,

       

      -Ken

        • Re: Nesting variables in the script
          Boris Gerchikov

          Hi Ken,

           

          The problem is $ sign in vTestFor$1

           

          set vCalcForXScript=if($(vTestFor1), 'Y', 'N');

           

          the script considers vTestFor$1 as a different variable, which is null.

           

          Thanks!

            • Re: Nesting variables in the script
              Ken van Mulder

              Hi Boris,

               

              The $1 is intentional as I want to be able to specify which function is called based on a parameter.

               

              For example: If vCalcForXScript is: if($(vTestFor$1), 'Y', 'N');

               

              Then in a chart, the following call would go through the translations:

               

                        $(vCalcForXScript(2))                     // original call

                        if($(vTestFor2), 'Y', 'N');          // substitute vCalcForXScript

                        if((Value=2), 'Y', 'N')                    // substitute vTestFor2

               

              Alternatively I could use: $(vCalcForXScript(3)) which would use the vTestFor3 variable.

               

              My problem is that if I were to set vCalcForX using the Variable Overview interface, it will work. If I attempt to set vCalcForX in the load script (as per the first post) it translates the variables immediately. (as you pointed out)

               

              I'm looking for a way to set vCalcForX to contain variables without translating them until later.

               

              Thanks,

               

              -Ken

            • Re: Nesting variables in the script
              Gysbert Wassenaar

              Option 1:

              let vCalcForXScript= 'if($' &'(vTestFor$1),' & chr(39) & 'Y' & chr(39) & ','  & chr(39) & 'N' & chr(39) & ')';

               

              Option 2:

              set vT =if(@(vTestFor@1), 'Y', 'N');

              let vCalcForXScript = replace('$(vT)', '@','$');