0
votes

I've got a tab-delimited text file that contains an unknown number of rows, and from Row 3 onwards has 11 columns.

Row 1 is simply the filename (without extension) of the text file, and Row 2 contains two integers that specify the numbers of Rows and Columns respectively that are needed in the DataGridView.

How can I get the data from Row 2 into two separate variables (type integer)? I'm guessing a Split statement or something but not quite sure...

(I know it's more useful to use For Each in my coding but I haven't got that far yet). Here's my coding so far:

Dim fileReader As System.IO.StreamReader
fileReader = My.Computer.FileSystem.OpenTextFileReader("C:\textfile.txt")
Dim stringReader As String
stringReader = fileReader.ReadLine()    ' read title
stringReader = fileReader.ReadLine()    ' read row & column values
TextBox1.Text = stringReader
1

1 Answers

0
votes

I have managed to figure out how to read from a tab delimited text file, but I still need to know how to add it to a DataGridView. Here's how I can read from the text file:

    Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(strHardwareQLT)
        MyReader.TextFieldType = FileIO.FieldType.Delimited
        MyReader.SetDelimiters(vbTab)

        Dim currentRow As String()
        currentRow = MyReader.ReadFields()    ' read Row 1
        currentRow = MyReader.ReadFields()    ' read Row 2
        currentRow = MyReader.ReadFields()    ' read Row 3
        Dim currentField As String
        For Each currentField In currentRow
            MsgBox(currentField)              ' this will show 3 MsgBox's
        Next
    End Using