?
Solved

Read tab-delimited text file into datagridview

Posted on 2008-10-22
3
Medium Priority
?
1,101 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
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.
Suggested Courses

770 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