hexagon logo

Import static data from textfile (fast hack)

Proof of concept.

Contents of data.txt:
Article: 988893
Description: pistons
Nr. Lot: 838384


How pc-dimis can import only the data "988893" , "pistons" and "838384
" from this file??


Code for reading:
FPTR       =FILE/OPEN,C:\Documents and Settings\CS-FC-SDE-S-PCID254\Desktop\data.txt,READ
            ASSIGN/ROW1=""
            ASSIGN/ROW2=""
            ASSIGN/ROW3=""
V1         =FILE/READLINE,FPTR,{ROW1}
V1         =FILE/READLINE,FPTR,{ROW2}
V1         =FILE/READLINE,FPTR,{ROW3}
            FILE/CLOSE,FPTR,KEEP
            ASSIGN/ROW1=ROW1-"Article: "
            ASSIGN/ROW2=ROW2-"Description: "
            ASSIGN/ROW3=ROW3-"Nr. Lot: "


Note that the contents of the three rows must match the static string that we are deleting from the line we read, otherwise it will not work. If you change the "Article: " to anything else, you must also change the "ROW1-"Article: " to match your change. This applies of course to the ROW2 and ROW3 contents as well.

An easy hack with no string verification or any of the fancy stuff. It builds on the fact that the source file "data.txt" only contains three rows with data that is interesting for us and these are the three first rows in the source file.
Parents
  • I think there is an even more direct way to do this:

    FPTR       =FILE/OPEN,C:\Documents and Settings\CS-FC-SDE-S-PCID254\Desktop\data.txt
    V1         =FILE/READLINE,FPTR,"Article:"+" "+{ROW1}
    V1         =FILE/READLINE,FPTR,"Description:"+" "+{ROW2}
    V1         =FILE/READLINE,FPTR,"Nr. Lot:"+" "+{ROW3}
                FILE/CLOSE,FPTR,KEEP


    This should read over the unwanted text and only store the desired characters in the variable.

    I'll double check it when I get to work but I'm pretty sure this will do the same thing. I haven't tried it with the desirable text at the beginning, or in the middle, of the line. VPT's method should work no matter where the text is located.

    UPDATE: Syntax above adjusted a bit. The static text that you want to ignore needs to match the text in the file exactly and it must be in "quotes". If there is a space in the string that needs to be ignored that needs to be separately defined as shown above.
Reply
  • I think there is an even more direct way to do this:

    FPTR       =FILE/OPEN,C:\Documents and Settings\CS-FC-SDE-S-PCID254\Desktop\data.txt
    V1         =FILE/READLINE,FPTR,"Article:"+" "+{ROW1}
    V1         =FILE/READLINE,FPTR,"Description:"+" "+{ROW2}
    V1         =FILE/READLINE,FPTR,"Nr. Lot:"+" "+{ROW3}
                FILE/CLOSE,FPTR,KEEP


    This should read over the unwanted text and only store the desired characters in the variable.

    I'll double check it when I get to work but I'm pretty sure this will do the same thing. I haven't tried it with the desirable text at the beginning, or in the middle, of the line. VPT's method should work no matter where the text is located.

    UPDATE: Syntax above adjusted a bit. The static text that you want to ignore needs to match the text in the file exactly and it must be in "quotes". If there is a space in the string that needs to be ignored that needs to be separately defined as shown above.
Children
No Data