创建文件文本时索引超出范围的异常

时间:2015-03-18 17:27:45

标签: vb.net text-files

fisrt我的英语不是很好(对此很难过).. 这个程序采用文本文件..它改变第4行然后导出它 我有两个错误 1-索引越界异常 2 - 导出的文件不会写入所有行 怎么了?

 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 个答案:

没有答案