title: VBS fast loop through lines
body: <p>I need to loop and permutate through 2000 lines of a text file(which will always increase in size), get the total length, and based on the length, i need to copy the two records to another file.
  The problem is that it takes to long to process everything. I am not sure that this is the best approach but any help is appreciated.</p>
  
  <pre><code>filename = "Jul2017.txt"
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile(filename)
  
  Do Until f.AtEndOfStream
      r1 = f.ReadLine
      Do Until f.AtEndOfStream
          r2 = f.ReadLine
          if len(r1 &amp; r2) &gt; 17 then
             'Do something
          end if
      Loop
  Loop
  
  WScript.Echo "Done!"
  f.Close
  </code></pre>
  
  <hr>
  
  <p>This should solve the loop nesting problem.</p>
  
  <pre><code>filename = "Jul2017.txt"
  
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile(filename, 1)
  
  For x = 1 to 2000
  r1 = f.ReadLine
  For z = 1 to 2000
  r2 = f.ReadLine
  if len(r1 &amp; r2) &gt; 17 then
  'Do something
  end if
  next
  next
  WScript.Echo "Done!"
  f.Close
  
  Input
  -----------
  TMM87R2
  YUU52R7VVB
  VLL73IOP3
  TMM54Y2
  VLL21CSZ
  YUU56
  VLL71BVR54
  ...
  </code></pre>
  
  <p>What i need to do: </p>
  
  <pre><code>First iteration
  TMM87R2 &amp; TMM87R2 &lt; 17 characters ( do nothing )
  TMM87R2 &amp; YUU52R7VVB &gt; 17 characters ( copy the lines )
  TMM87R2 &amp; VLL73IOP3 etc.
  ...
  TMM87R2 &amp; VLL71BVR54
  
  Second iteration
  YUU52R7VVB &amp; TMM87R2
  YUU52R7VVB &amp; YUU52R7VVB
  ...
  
  Until last iteration
  VLL71BVR54 &amp; VLL71BVR54
  </code></pre>
  
  <p>Each line should be "placed" next to each line in the file and if the total size is excedes 17 characters,
  copy the two records to another file. I know i am looping 2000 times and it is repetitive but the order of records matters.</p>