Read file ignoring headers

I need to read in a text file, but ignoring the headers in it. My code is below, to add columns to a Listbox, but I need to start reading the file from the second row.

If f <> Nil And f.Exists Then
  Var tab as String = ChrB(58)
  textInput = TextInputStream.Open(f)
   textInput.Encoding = Encodings.UTF8
  While Not textInput.EndOfFile
    rowFromFile = textInput.ReadLine
    If Listbox.ColumnCount < rowFromFile.CountFields(tab) Then
      Listbox.ColumnCount = rowFromFile.CountFields(tab)
    End If
    Listbox.AddRow("")
    Var row as integer = 1
    for i = 1 to rowFromFile.CountFields(tab)
      oneCell = rowFromFile.NthField(tab, i)
      Listbox.CellValueAt(Listbox.LastAddedRowIndex, i  - 1) = oneCell
    Next
  Wend
  textInput.close
End If

why not just add a line right before the While loop that says

Call textInput.ReadLine
1 Like

Perhaps you may keep a line count as you go and skip the first one. Something like:

var LineCount as integer = 0
If f <> Nil And f.Exists Then
  Var tab as String = ChrB(58)
  textInput = TextInputStream.Open(f)
   textInput.Encoding = Encodings.UTF8
  While Not textInput.EndOfFile
    rowFromFile = textInput.ReadLine
    LineCount = LineCount +1
    If Listbox.ColumnCount < rowFromFile.CountFields(tab) Then
      Listbox.ColumnCount = rowFromFile.CountFields(tab)
    End If
    Listbox.AddRow("")
    Var row as integer = 1
 If LineCount > 1 then
    for i = 1 to rowFromFile.CountFields(tab)
      oneCell = rowFromFile.NthField(tab, i)
      Listbox.CellValueAt(Listbox.LastAddedRowIndex, i  - 1) = oneCell
    Next
 end if
  Wend
  textInput.close
End If

edit: @Greg_O_Lone suggestion is simpler and more elegant, and achieves the same goal. Did not see it when I posted.

Isn’t

LB.AddRow Split(rowFromFile, Chr(9)) // Better / Faster ?

Also, using ListBox.AddRow "" is allowed ? Of course, I prefer to use LB until I have more than one ListBox, then I add a well named suffix…

That used to be the preferred way to do it.

ListBox part, not AddRow part.

At first, I was asking myself where my head was when I read it, then I remember why I wrote that…

It is understood that you can’t name a control “ListBox”. When we see that on the forum it is just a placeholder for the actual control’s name.

I think so, but read the code at the top of this thread: it does not looks like “fake” code.

Administrator: please add a “1” at the end of each occurence before someone believes it is allowed, then complain because it does not works as advertised.

Things like that have been read/heard at technical support…