-2

i want to read text file and from the fifth line take only the first column before (;) this my code to browse and read text :

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim OpenFile As New OpenFileDialog
        OpenFile.FileName = ""
        OpenFile.Filter = "Fichier Texte (*.pnp)|*.pnp"
        OpenFile.ShowDialog()
        Try
            Dim lire As New System.IO.StreamReader(OpenFile.FileName)
            RichTextBox1.Text = lire.ReadToEnd
            lire.Close()
        Catch ex As Exception

        End Try
    End Sub
End Class

help me please

5
  • 1
    What is a pnp file? Is it semicolon delimited?
    – Sam Axe
    Mar 9, 2015 at 11:32
  • no it's an extension like txt Mar 9, 2015 at 11:53
  • the code of semicolon delimited is not include Mar 9, 2015 at 11:54
  • i hope you have solution to my problem Mar 9, 2015 at 12:09
  • Please add a relevant sample of your file to the question. Mar 9, 2015 at 15:40

1 Answer 1

1

You could try something like this:

    Dim lineYouWantToRead As Int32 = 5
    Dim fieldYouWantToRead As Int32 = 1
    Dim capturedValue As String = ""

    Using fileReader As New FileIO.TextFieldParser(OpenFile.FileName)
        fileReader.TextFieldType = FileIO.FieldType.Delimited
        fileReader.SetDelimiters(";")
        While fileReader.LineNumber <= lineYouWantToRead - 1
            Dim currentLine As String() = fileReader.ReadFields()
            capturedValue = currentLine(fieldYouWantToRead - 1)
        End While
    End Using

    RichTextBox1.Text = capturedValue

Let us know if that is any help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.