title: VBscript gives out of range error with arrays within loop but not with arrays outside
body: <p>I am getting a "Subscript out of range error" on line 23 of my code. I am opening and reading a .csv file and trying to return the data of the last line. The input information looks like this:</p>
  
  <pre><code>Control Unit
  Date,Time,Seconds,V1,V2,V3,V4,
  07/12/2013 ,11:27:21 ,0 ,Closed ,Closed ,Closed ,Closed ,
  07/12/2013 ,11:27:22 ,1 ,Closed ,Closed ,Closed ,Closed ,
  </code></pre>
  
  <p>Outside of the while loop if I say WScript.Echo = strValues(3) then it echoes the right data, but if I try the same thing within the loop, then I simply get an out of range error for anything other than strValues(0). I don't understand this because if I check the strValues array once the while loop is complete I can call any of the 7 elements.</p>
  
  <pre><code>Option Explicit
  Dim first, secnd 
  Dim fso, inputFile 
  Dim strSource, strLine, strValues
  Const ForReading = 1
  
  'Create the file system object
  Set fso = CreateObject("Scripting.FileSystemObject")
  
  'Initialize a few items
  strSource = "C:\Testing\data.csv"
  
  'Open the source file to read it
  Set inputFile = fso.OpenTextFile(strSource,ForReading)
  
  'Read the file line by line
  Do while not inputFile.AtEndOfStream
      strLine = inputFile.ReadLine
      'Split the line on the comma into an array
      strValues = Split(strLine, ",")
      'Check if the dq number matches
      first = strValues(0)
      'secnd = strValues(3) 'here it tells me its out of range
  Loop
  WScript.Echo strLine  'once the loop is over it gives me the values just fine
  Wscript.Echo strValues(1)
  secnd = strValues(3) 'this gives no error
  'Close the file
  inputFile.Close
  
  'Clean up
  Set inputFile = Nothing                                                                           
  Set fso = Nothing
  </code></pre>
  
  <p>Thanks</p>