0

fisrt i'm not very good in english (so sad for that) .. this program take a text file .. it change the 4th row then export it i got two errors 1- index out of bounds exception 2-the exported file doesn't write all lines what wrong?

 Protected Sub traitement(ByVal input As String, ByVal output As String)
        Dim sr As New StreamReader(input)
        Dim sw As StreamWriter = New StreamWriter(output)
        Dim rows() As String = Nothing
        Dim val As String = Nothing
        Dim line As String
        Dim ar As New ArrayList
        Dim nbr As Integer = File.ReadAllLines(input).Length
        Try
            For i As Integer = 0 To nbr - 1

                line = sr.ReadLine
                rows = line.Split(";")
                If rows(4).StartsWith("24") = True Then
                    val = rows(4).Replace("24", "00")
                Else
                    val = rows(4)
                End If

                Dim newline As String = rows(0) & ";" & rows(1) & ";" & rows(2) & ";" & rows(3) & ";" & val & ";" & rows(5)

                ar.Add(newline)
                sw.WriteLine(ar(i))
            Next i

            ' sr.Close()
            ' sw.WriteLine(ar)

            sw.Flush()
            MessageBox.Show("traitement terminé")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

0 Answers0