4 Replies Latest reply: Jun 20, 2014 5:14 AM by Friedrich Hofmann RSS

    How does this code work?Creating variables using loop

    Balraj Prabhu

      @Hi,

       

      I stumbled across this code while studying a dashboard built by another developer.

      At a high level I thing I know ( I'm not sure ) what happening in this code.

      Has anyone used this code before

       

      Could someone explain what's happening here.

       

       

      qvCommunity.png

        • Re: How does this code work?Creating variables using loop
          Gysbert Wassenaar

          The code first loads variable names and the contents for the variables from an excel file into the table CommonVariables. In the for-loop it iterates through each record of the table CommonVariables and retrieves the variable name and the variable contents. It the creates the variable in the qlikview document and assigns the variable contents to the variable. The NoOfRows function is used to find the number of records of the CommonVariables table, i.e. the number of variables that should be created. The peek function is used to look up the values of the fields from the i-th record.

          • Re: How does this code work?Creating variables using loop
            Bruno Souza

            Hello.

             

            The code does exactly what you think: it does create new variable inside the loop.

             

            The purpose of it, i guess, is that you can maintain a single xls full variables common to all your application and use the code to load the variables from the excel file.

             

            Regards

            • Re: How does this code work?Creating variables using loop
              Clever Anjos

              This code opens a excel file and creates as many variables (one per line) as rows on [Common Variables] sheet

                • Re: How does this code work?Creating variables using loop
                  Friedrich Hofmann

                  Hi,

                   

                  just a few words to add for anyone else looking at this - I just spent around 20min figuring out the details

                  of the code above. Of course it does work, but there are a few loopholes:

                   

                  - both the name of the variable as you want it and the table_name must be in quotes (that's correct here, but it's
                     important)

                  - The field 'VarFormula' that is referenced in the code must contain ONLY the value, not the complete SET command
                     or anything ... (and keep in mind the decimal_separator_settings in QlikView might not match those in Excel)

                  - For the first record, i must have the value 0 (not 1) - you can look that up in the help_file, but it's always possible to
                     get it wrong ;-)

                   

                  HTH

                   

                  Best regards,

                   

                  DataNibbler