Solved

Read tab-delimited text file into datagridview

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now