title: Read text file and name buttons VB.NET
body: <p>What I wan't to do is to read a text file with 1, 2, 3, 4 or 5 lines.
  If the text file is completely full (5 lines) then the code works.</p>
  <p>But the code needs to work when there are only 3 lines in the text file.
  So eventually you get 3 buttons with names and 2 without.</p>
  <p>The code:</p>
  <pre><code>Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  
          Dim Lines() As String = IO.File.ReadAllLines(file)
  
          Dim Ordernummer1 As String
          Dim Ordernummer2 As String
          Dim Ordernummer3 As String
          Dim Ordernummer4 As String
          Dim Ordernummer5 As String
  
          Dim Regels As New List(Of String)
          Select Case Lines.Count
              Case 1
                  Lines(1) = &quot;&quot;
                  Lines(2) = &quot;&quot;
                  Lines(3) = &quot;&quot;
                  Lines(4) = &quot;&quot;
              Case 2
                  Lines(2) = &quot;&quot;
                  Lines(3) = &quot;&quot;
                  Lines(4) = &quot;&quot;
              Case 3
                  Lines(3) = &quot;&quot;
                  Lines(4) = &quot;&quot;
              Case 4
                  Lines.add(4) = &quot;&quot;
              Case 5
                  'nothing
  
          End Select
  
          MsgBox(Lines(0))
          last = Lines(0).Substring(Lines(0).LastIndexOf(&quot;\&quot;) + 1)
          MsgBox(last)
          Ordernummer1 = last.Substring(0, last.IndexOf(&quot; &quot;))
          MsgBox(Ordernummer1)
          Button12.Text = Ordernummer1
  
          MsgBox(Lines(1))
          last = Lines(1).Substring(Lines(1).LastIndexOf(&quot;\&quot;) + 1)
          MsgBox(last)
          Ordernummer2 = last.Substring(0, last.IndexOf(&quot; &quot;))
          MsgBox(Ordernummer2)
          Button13.Text = Ordernummer2
  
          MsgBox(Lines(2))
          last = Lines(2).Substring(Lines(2).LastIndexOf(&quot;\&quot;) + 1)
          MsgBox(last)
          Ordernummer3 = last.Substring(0, last.IndexOf(&quot; &quot;))
          MsgBox(Ordernummer3)
          Button14.Text = Ordernummer3
  
          MsgBox(Lines(3))
          last = Lines(3).Substring(Lines(3).LastIndexOf(&quot;\&quot;) + 1)
          MsgBox(last)
          Ordernummer4 = last.Substring(0, last.IndexOf(&quot; &quot;))
          MsgBox(Ordernummer4)
          Button15.Text = Ordernummer4
  
          MsgBox(Lines(4))
          last = Lines(4).Substring(Lines(4).LastIndexOf(&quot;\&quot;) + 1)
          MsgBox(last)
          Ordernummer5 = last.Substring(0, last.IndexOf(&quot; &quot;))
          MsgBox(Ordernummer5)
          Button16.Text = Ordernummer5
  </code></pre>