Imports System.IO
Public Class Form1Dim isContinue As Boolean = TruePrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.ClickTextBox1.Text = ""isContinue = TrueOpenFileDialog1.Filter = "CSV Files(*.CSV;*.TXT)|*.CSV;*.TXT"If OpenFileDialog1.ShowDialog = DialogResult.OK ThenUsing MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(OpenFileDialog1.FileName)MyReader.TextFieldType = FileIO.FieldType.DelimitedMyReader.SetDelimiters(",")Dim currentRow As String()Dim nowLn = 0While Not MyReader.EndOfDataTrycurrentRow = MyReader.ReadFields()Dim currentField As StringDim strLn As String = ""For Each currentField In currentRowstrLn &= currentField & " "NextTextBox1.Text &= strLn & vbCrLfupdateProcess(nowLn + 1)nowLn += 1Application.DoEvents()If Not isContinue ThenExit WhileEnd IfCatch ex As Microsoft.VisualBasic.FileIO.MalformedLineExceptionMsgBox("行" & ex.Message & "無(wú)效,已經(jīng)跳過(guò)")End TryEnd WhileEnd UsingEnd IfEnd SubPrivate Sub updateProcess(nowValue As Long)Label1.Text = "讀取第" & nowValue & "行"End SubPrivate Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.ClickisContinue = FalseEnd Sub
End Class