amelia zaripova
amelia zaripova

Reputation: 1

how to call on a new line in ReadFields?

In ASP.net vb, I am reading a .txt file and want to assign a variable to each field in the file. So far I have

Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("SomePath\SomeFile.txt")

MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")

Dim currentRow As String()
currentRow = MyReader.ReadFields
A1 = currentRow(0)
A2 = currentRow(1)
A3 = currentRow(2)

I have three fields in each row, so this allows me to assign variables to the 3 fields in the first row which are separated by commas. However, I am having difficulty accessing the next row to create new variables for the following fields. Any ideas how I could assign variables to all the fields in this .txt file? I am very new to this so any help would be much appreciated.

Upvotes: 0

Views: 187

Answers (1)

dbasnett
dbasnett

Reputation: 11773

Something like this

    Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("SomePath\SomeFile.txt")
        MyReader.TextFieldType = FileIO.FieldType.Delimited
        MyReader.SetDelimiters(",")
        While Not MyReader.EndOfData
            Dim currentRow() As String
            currentRow = MyReader.ReadFields
            A1 = currentRow(0)
            A2 = currentRow(1)
            A3 = currentRow(2)
        End While
    End Using

edit based on comment

            Dim currentRow() As String
            currentRow = MyReader.ReadFields
            A1 = currentRow(0)
            A2 = currentRow(1)
            A3 = currentRow(2)

            'repeat as many times as necessary to get to 15 vars 

            currentRow = MyReader.ReadFields
            A4 = currentRow(0)
            A5 = currentRow(1)
            A6 = currentRow(2)

Upvotes: 0

Related Questions