I understand the error but I don't know why I am getting it. I have a tab delimited file that I am reading line by line. The line it fails on in the file is the last one and gives the error
The error points to this lineCode:0000.24c5.eaac 8 Sec1 Of00 0007.e788.a2d3 Cam 9 Sec1
RowItem(4) = RowItem(4).TrimEnd(RowItem(4), vbCrLf)
There is a tab between Cam and 9 and as the same with the line above it.
Code:Dim Contents = IO.File.ReadAllLines("file1.txt").ToList Dim Contents2 = IO.File.ReadAllLines("file2.txt").ToList Dim StrippedMAC As String Dim NewRoom As String Contents.RemoveAt(0) Contents2.RemoveAt(0) Dim RowItem() As String For x As Integer = 0 To Contents.Count - 1 RowItem = Contents(x).Split(vbTab) RowItem(4) = RowItem(4).TrimEnd(RowItem(4), vbCrLf) ' <------ Error Line If RowItem(4).ToString.Length > 1 Then NewRoom = "Room " & RowItem(0).ToString & " " & RowItem(1).ToString StrippedMAC = Replace(CStr(RowItem(4)).ToString, ".", "") For i = 0 To Contents2.Count - 1 ' Contents2(i) = Contents2(i).Substring(0, Contents2(i).Count - 1) Dim RowItem2 = Contents2(i).Split(vbTab) If Not RowItem2(6).ToString = "NULL" And StrippedMAC = RowItem2(6).ToString Then ' If Not RowItem2(6).ToString = "NULL" Then DataGridView1.Rows.Add(RowItem) ElseIf Not NewRoom = RowItem2(7).ToString Or RowItem2(7).ToString = "NULL" Then DataGridView1.Rows.Add(RowItem) End If Next End If Next End If End Sub




Reply With Quote