Process a text file line by line

Share your macros, knowledge, solutions, services, ...
Post Reply
Petr
Posts: 106
Joined: Tue Oct 18, 2016 1:12 pm

Process a text file line by line

Post by Petr » Wed Nov 23, 2016 4:39 pm

This example shows how to read text file line-by-line and process the lines.

Code: Select all

<#> Start of the macro
<cmds>

<#> Show input form for variable vInputFile  
<var_oper>(vFile,"",SELECT_FILE,"Select File","", "0")

<#> Esc or Cancel pressed - then exit macro
<if_str>("_vCanceled==1")
   <exitmacro>
<endif>

<#> Load data from file to variable
<data_load>("vbTemp_FileText","%vFile%","")

<if_str>("_vErr==NO")
   <#> Get number of lines
   <var_oper>(vbTemp_NumOfLines,"vbTemp_FileText",TEXT_GET_NUMOFLINES,"","", "0")

   <#> Do for each line
   <begloop>(vbTemp_NumOfLines)

      <#> Store current line in to variable vbLine
      <var_oper>(vbLine,"vbTemp_FileText",TEXT_GET_LINE,"_vLoopCounter","", "0")

      <#> Show message
      <msg>(-100,-100,"INSTEAD OF THIS MESSAGE, YOU CAN DO YOUR OWN FILE LINE PROCESSING.
       
      Line number:
      %_vLoopCounter%
     
      Line content:
      %vbLine%
      ","Message",1)

   <endloop>
<else>
   <#> Cannot load text file, show error 
   <msg>(100,100,"_vError","Error",1)
<endif>

<#> End of the macro

Post Reply