Solved

Read tab-delimited text file into datagridview

Posted on 2008-10-22
3
1,094 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 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

726 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