title: VB.NET Index out of Range exception related to text file
body: <p>I have some code I have used many times over which has always worked great for me.  The latest use, however, throws an exception under certain circumstances that I cannot seem to resolve.  Here it is:</p>
  <p>I read from a text file to an array, use it as a binding source for some of my controls (it autofills 3 controls based on the selection of a single control). I created a Student class with 4 properties (Name, ID, DOB and DOE).  Here is the code I use:</p>
  <pre><code>Private Sub autoFill()
          Dim rost As String = &quot;Roster.txt&quot;
          Dim lines As List(Of String) = File.ReadAllLines(rost).ToList
          Dim list As List(Of Student) = New List(Of Student)
          For i As Integer = 0 To lines.Count - 1
              Dim data As String() = lines(i).Split(&quot;:&quot;)
              list.Add(New Student() With {
                       .StudentName = data(0),
                       .StudentID = data(1),
                       .StudentDOB = data(2),
                       .StudentDOE = data(3)
                                          })
          Next
          StudentBindingSource.DataSource = list
  
  
      End Sub
  </code></pre>
  <p>Now here is the problem.  In the &quot;For&quot; loop when I set i to 0 to lines.count -1 it throws this error:</p>
  <p><a href="https://i.stack.imgur.com/Dm5Oe.jpg" rel="nofollow noreferrer">VB&gt;NET EXCEPTION</a></p>
  <p>However...If I change i to 1 instead of 0 it works OR if I take away data(2) and data(3) it works with i = 0.  I would prefer to use 0 so that I can have a blank line in the combobox or &quot;--choose--&quot;, etc.  The only thing I have thought that might be useful is that my first row in the text file has nothing to split.  Here is the line format of the text file:</p>
  <pre><code>Student Name         ID#        DOB          DOE      &lt;-----This header row is NOT in the text file
  Last Name, First Name : 0000000 : 01/01/2021 : 01/01/2021
  </code></pre>
  <p>I'm going to assume I'm missing something really simple here.  Any guidance would be greatly appreciated!  Thank you.</p>