Visual Studio Development Bookmark and Share   
 index > Visual Basic Express Edition > Not getting all 17,000 rows in text file, only getting about 2,500 rows when using StreamReader
 

Not getting all 17,000 rows in text file, only getting about 2,500 rows when using StreamReader

I'm trying to parse a text file (actual TXT Text File: 150 MB), and when using StreamReader to do a 'ReadLine', the last line I get when either using "if line is nothing" or "if sr.EndfStream" is at row 2,486.

When importing it into Excel though, I'm getting over 17,000 rows.

What am I doing wrong?

        Try
            Dim TempDT As New DataTable
            Dim LineCount As Int32

            TempDT.Columns.Add("One")

            ' Create an instance of StreamReader to read from a file.
            Using sr As StreamReader = New StreamReader(f.T5_txtPathAndFileName.Text)
                Dim line As String
                ' Read and display the lines from the file until the end 
                ' of the file is reached.
                Do

                    line = sr.ReadLine()

                    If line IsNot Nothing Then
                        TempDT.Rows.Add(line)
                    End If

                    LineCount += 1
                Loop Until line Is Nothing
            End Using

            Return TempDT
        Catch ex As Exception

        End Try
Please help
Newbie
jlroper  Saturday, October 17, 2009 1:38 PM
If you get the number of rows you expect with ReadAllLines, your code is flawed. If not, the file is flawed.
  • Marked As Answer byjlroper Saturday, October 17, 2009 2:27 PM
  •  
JohnWein  Saturday, October 17, 2009 1:48 PM
If you get the number of rows you expect with ReadAllLines, your code is flawed. If not, the file is flawed.
  • Marked As Answer byjlroper Saturday, October 17, 2009 2:27 PM
  •  
JohnWein  Saturday, October 17, 2009 1:48 PM

That was it ,JohnWein. When usingthe 'ReadAllLines'method I found that thefile as corrupt (which was a much quicker way to get the array of the lines I needed). Put in code for others to know the quicker way.

Dim

line() As String = System.IO.File.ReadAllLines(f.T5_txtPathAndFileName.Text)



Thank you.


Newbie
jlroper  Saturday, October 17, 2009 2:27 PM

You can use google to search for other answers

Custom Search

More Threads

• How can I prevent NumericUpDown value from changing under certain conditions?
• Cannot create new database
• Events Triggering
• process changing
• Database not updated?
• Changing PictureBoxSizeMode in MouseHover event picks up a stray image
• search throught richtextbox
• Getpixel API
• vs2003 to vs2005 - convert code
• Distributing Files over a Network using A Spreadhsheet and Windows file Shares