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
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.
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…