Solved

Read tab-delimited text file into datagridview

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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.

821 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