Solved

Read tab-delimited text file into datagridview

Posted on 2008-10-22
3
1,075 Views
Last Modified: 2013-11-26
The attached file is a copy of a file that I need to read into a datagridview.

What I need to do is skip the first 17 lines and then check if the UBOUND is > 2 and begin reading the file
and when the UBOUND < 2 to stop.

Thank you in advance.
example.txt
0
Comment
Question by:aothomas42
  • 2
3 Comments
 
LVL 14

Expert Comment

by:raja_ind82
ID: 22778360
0
 

Author Comment

by:aothomas42
ID: 22778559
Ok i got that. How do I skip lines though. And can I do a myarray.length to get the number of values in the array
0
 
LVL 14

Accepted Solution

by:
raja_ind82 earned 500 total points
ID: 22780773
   Public Sub ReadFile(ByVal fileName As String)

        Using reader As New TextFieldParser(fileName)

            reader.TextFieldType = FieldType.Delimited

            ' Set the delimiters for comma separated text
            reader.Delimiters = New String() {vbTab}

            Dim currentRow As String()
            Dim i As Integer

            'Loop through all of the fields in the file.
            'If any lines are corrupt, report an error and continue parsing.
            While Not reader.EndOfData
                Try
                    i = i + 1
                    currentRow = reader.ReadFields()
                    If (i > 17) And UBound(currentRow) > 2 Then
                        MsgBox(currentRow(0))
                    End If
                    ' Include code here to handle the row.
                Catch ex As MalformedLineException
                    MsgBox("Line " & ex.Message & " is invalid.  Skipping")

                End Try
            End While
        End Using

    End Sub

if this process is continuing in the same file you ahve to drive logic for this...

Regards,
M.Raja
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question