Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
Qlik Analytics Tour 2020 Online. Begins August 10th. Register Today
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Creator II
Creator II

How does this code work?Creating variables using loop

@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

1 Solution

Accepted Solutions
Highlighted
MVP & Luminary
MVP & Luminary

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

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.


talk is cheap, supply exceeds demand

View solution in original post

4 Replies
Highlighted
MVP & Luminary
MVP & Luminary

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

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.


talk is cheap, supply exceeds demand

View solution in original post

Highlighted
Creator III
Creator III

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

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

Highlighted
Employee
Employee

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

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

Highlighted
Champion
Champion

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

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