TextFieldParser.ErrorLine 屬性

定義

傳回造成最新 MalformedLineException 例外狀況的行。

public:
 property System::String ^ ErrorLine { System::String ^ get(); };
public string ErrorLine { get; }
member this.ErrorLine : string
Public ReadOnly Property ErrorLine As String

屬性值

行,其造成最近的 MalformedLineException 例外狀況。

範例

這個範例會 ErrorLine 使用 屬性來顯示造成目前 MalformedLineException 例外狀況的行。

Dim FileReader As Microsoft.VisualBasic.FileIO.TextFieldParser
FileReader = My.Computer.FileSystem.OpenTextFieldParser("C:\test.txt")
Dim currentRow As String()
While Not FileReader.EndOfData
    Try
        currentRow = FileReader.ReadFields
        For Each currentField As String In currentRow
            My.Computer.FileSystem.WriteAllText(
                "C://testfile.txt", currentField, True)
        Next
    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
        MsgBox("Line " & FileReader.ErrorLine & " is not valid.")
    End Try
End While

備註

如果未擲回任何 MalformedLineException 例外狀況,則會傳回空字串。

屬性 ErrorLineNumber 可用來顯示造成例外狀況的行號。

下表列出涉及 屬性的工作 ErrorLine 範例。

收件者 請參閱
從分隔的檔案讀取 作法:從逗號分隔文字檔讀取
從固定寬度檔案讀取 作法:從固定寬度的文字檔讀取

適用於

另請參閱