【发布时间】:2016-06-02 00:46:28
【问题描述】:
我有一个 Streamreader,它在检查 Daycounts.txt 中的每一行后出现错误。它不是一个稳定的 txt 文件。其中的弦线并不稳定。行数不断增加或减少。这就是我使用 0 到 167 范围的原因。但是
这是Daycounts.txt的内容:Daycounts
Dim HourSum as integer
Private Sub Change()
Dim R As IO.StreamReader
R = New IO.StreamReader("Daycounts.txt")
Dim sum As Integer = 0
For p = 0 To 167
Dim a As String = R.ReadLine
If a.Substring(0, 2) <> "G." Then
sum += a.Substring(a.Length - 2, 2)
Else
End If
Next
HourSum = sum
R.Close()
End Sub
【问题讨论】:
-
改用 File.ReadAllLines
-
我该怎么做?我也用过这个:Dim a As String = R.ReadToEnd not working as well
标签: vb.net error-handling