Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to retrieve information from .txt to variable

Hi , i have a file (.txt ) , and i want to load the information in it into a variable . The structure of this file is :

201403

201305

...
what i want to do is to load into two variables one for the month and one for the year how can i do this , if you need more information to help me , tell me and i'll explain more
Thank you

1 Solution

Accepted Solutions
Not applicable
Author

Hi Kamy,

Please use the code below. Remember to put a field name (Variables in the exaple) into the first row of your text file.

text file structure:

    

     Variables

     201403

     201405

     ...

Qlikview script:

     Variables:

     LOAD Variables FROM c:\file.txt (txt, utf8, embedded labels, delimiter is '\t', msq); //here all the file rows are readed

     LET Variable1 = peek( 'Variables', 0 ); //0 is the first row

     LET Variable2 = peek( 'Variables', 1 ); //1 is the second row

     ...

     If you need a lot of variables do a loop and use an incremental variable into the second parameter instead a number.

Let me know if it works.

Regards.

View solution in original post

3 Replies
Not applicable
Author

Hi Kamy,

Please use the code below. Remember to put a field name (Variables in the exaple) into the first row of your text file.

text file structure:

    

     Variables

     201403

     201405

     ...

Qlikview script:

     Variables:

     LOAD Variables FROM c:\file.txt (txt, utf8, embedded labels, delimiter is '\t', msq); //here all the file rows are readed

     LET Variable1 = peek( 'Variables', 0 ); //0 is the first row

     LET Variable2 = peek( 'Variables', 1 ); //1 is the second row

     ...

     If you need a lot of variables do a loop and use an incremental variable into the second parameter instead a number.

Let me know if it works.

Regards.

Not applicable
Author

yes that's correct , please i need to know if i can do like this :

     if (peek( 'Variables', 0 )<=9, //here I want to concatenate the variable with zero)

     for exemple :  if the value is 3 it should become 03

thks for your help

Not applicable
Author

Hi Kamy,

     No, you can't do it directly with the PEEK sentence but using a conditional will work (if you need to do a loop it will      work too):

     Variables:

          LOAD Variables FROM c:\file.txt (txt, utf8, embedded labels, delimiter is '\t', msq);

          LET Variable1 = peek( 'Variables', 0 ); //0 is the first row

          LET Variable2 = peek( 'Variables', 1 ); //1 is the second row

     IF $(Variable1) <=9 THEN

            LET Variable1 = 0 & $(Variable1);

     ENDIF

     Let me know if this works.

Regards.