Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
datanibbler
Champion
Champion

Generate variables from an Excel file


Hi,

in principle I know how to generate variables from an Excel file.

In this instance, what I have to do is generate variables in the script that will be filled with a value only on the GUI, once a selection has been made on a field.

Manually, I have to type >> SET [varname] = = [fieldname] << => that way, the variable will be filled on the GUI once the user has made a selection on that field.

=> What would have to be the syntax for this in a loop when I want to parse my Excel_file row by row and generate that statement?

I can't seem to get it right.

Thanks a lot!

Best regards,

DataNibbler

3 Replies
datanibbler
Champion
Champion
Author

OK, I did it.

I just needed another line or two inside the loop as I couldn't seem to be able to do it in one go.

Now it is all dynamic - well, the variables anyway - they get created in the script, but will be filled with a value based on a selection by the user.

This is solved then.

The code now looks like this (based on an Excel file with the fields > Originalname < (the original fieldname), > Kurzname < (the fieldname without blanks).

FOR i = 0 TO NoOfRows('Berechtigungen_pre')
 
LET v_VarName = 'edit_' & PEEK('Kurzname', $(i), 'Berechtigungen_pre');
 
LET v_VarValue = chr(91) & PEEK('Originalname', $(i), 'Berechtigungen_pre') & chr(93);
 
LET v_statement_pre = '$(v_VarName)' & ' = = ' & '$(v_VarValue)' & ';';
 
LET v_statement = 'SET ' & '$(v_statement_pre)';
 
$(v_statement);
NEXT

Best regards,

DataNibbler

marcus_sommer

Hi DataNibbler,

you mean something like this: Re: How does this code work?Creating variables using loop.

- Marcus

datanibbler
Champion
Champion
Author

Hi Marcus,

yes, I do. This is actually solved already - my post is still being moderated 😉 The admins should use some kind of logic to not pick posts which mark a thread as closed for moderation if they cannot do it any faster ...

Only, that code generates fixed variables with exactly one value that is fixed in the script.

I needed variables to be generated in the script, but filled with values only on the GUI, when the user has made a selection on a field - they are to display the exact contents of a field, only with the possibility of editing it, given the logged-on user has the privileges of editing on this field.

Thanks anyway!

Best regards,

DataNibbler