Hi Guys, I have this problem which I encountered a while back in Java, and I worked through that at the time, however, know I'm using VB.net and am not really sure how to tackle this.

I am trying to read a text file line by line, using the following method
I have some getter/setter methods, and declarations not shown here

Dim TextLine As String
        Dim TextLineParts() As String

        If System.IO.File.Exists(FILE_NAME) = True Then
            ' Dim objReader As New System.IO.StreamReader(FILE_NAME)

            ' Do While objReader.Peek() <> -1
            For Each line As String In System.IO.File.ReadAllLines(FILE_NAME)
                ' TextLine = objReader.ReadLine()
                TextLineParts = line.Split("|")


                Dim dc As New DocumentComments
                dc.setRefNum(TextLineParts(0))
                dc.setComment(TextLineParts(1))
                dc.setTimeStamp(TextLineParts(2))

                getComments().Add(dc)
                '  Loop
            Next
        Else
            MsgBox("File Does Not Exist")
        End If

As you may notice, I have tried to use both .peek method (with object reader and Do While construct, which are commented) and the For Each line..

I want to read a text file which consists of several lines of text.
These lines are separated by (white space)a new line, and each line is delimited with a pipeline, something like so :

1stpart|2ndpart|3rdpart
4thpart|5thpart|6thpart
7thpart|8thpart|9thpart

Each line has 3 fields in which the first field of each line, I want to store them in an arraylist at position 0, second field of each line in arraylist at postion 1, so on and so forth.

The loop is set to run as many times as the number of lines and for each line I m creating a new instance of my class, dc in order to store them in the arraylist getComments()

I tested if it works by creating a display method

    Public Sub DisplayComments()
        For Each dc In getComments()
            Form1.RichTextBox1.Text = dc.getComment
        Next

    End Sub

The result I'm getting is the correct field, however, im getting only the correct field of the last line.
So in regards to my example, from the following text stored in my text file
1stpart|2ndpart|3rdpart
4thpart|5thpart|6thpart
7thpart|8thpart|9thpart

Result displayed is "7thpart", and what I want is "1stpart, 4thpart, 7thpart"

I would be very grateful if any of you can point out my mistakes and any ignorant flaws.

Thanks
C.N.

I am forced to conclude by the syntax "getcomments()" that getcomments is a function that returns an ArrayList. Howerver without seeing that function it is not possible offer any insite as to why this is happening.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.