Send data from a csv to an array

Asked

Viewed 30 times

0

I need to send the data that is in a csv file into an array.

I already have the importer of the csv file and it is read only need to send the data to the array.

------edited-------

Using the Infragistics.Documents.Excel I already have access to the csv document, and now I need to send the data of each row to an array.

  • José, explain your question better, add more details, examples, or even what you already have. So they can help you.

2 answers

0

Try it like this:

Dim arrName() As String
Dim arrValue() As String

Using ioReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\test\test.csv")

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

    While Not ioReader.EndOfData

        Dim arrCurrentRow As String() = ioReader.ReadFields()

        If arrName Is Nothing Then

            ReDim Preserve arrName(0)
            ReDim Preserve arrValue(0)

            arrName(0) = arrCurrentRow(0)
            arrValue(0) = arrCurrentRow(1)

        Else

            ReDim Preserve arrName(arrName.Length)
            ReDim Preserve arrValue(arrValue.Length)

            arrName((arrName.Length - 1)) = arrCurrentRow(0)
            arrValue((arrValue.Length - 1)) = arrCurrentRow(1)

        End If

    End While
  • Pedro didn’t work ...

0


I managed to resolve with

Dim iRow As Integer = 1
                Dim iCol As Integer = 0

                Dim valores As String



                While oWorksheet.Rows(iRow).Cells(iCol).Value IsNot Nothing
                    valores = oWorksheet.Rows(iRow).Cells(iCol).Value
                    iCol += 1
                End While

Browser other questions tagged

You are not signed in. Login or sign up in order to post.