0

What I am trying to do is take a CSV file and import it into an array. Then access the data to be used in an equation later.

Public Function ReadCVSFile()
    'load the file
    strfilename = "C:\Users\Owner\Documents\Pokemon DnD stuff\Pokemon DnD\Full Info Spreadsheet Text"
    'check if the file exists
    If File.Exists(strfilename) Then
        Dim tmpstream As StreamReader = File.OpenText(strfilename)
        Dim strlines() As String
        Dim strline() As String
        Dim ArrayX As Integer
        Dim ArrayY As Integer

        strlines = tmpstream.ReadToEnd().Split(Environment.NewLine)

        'redimension the array to fit
        num_rows = UBound(strlines)
        strline = strlines(0).Split(",")
        num_cols = UBound(strline)
        ReDim strArray(num_rows, num_cols)

        'copy the data into the redimensioned array
        For ArrayX = 0 To num_rows
            strline = strlines(ArrayX).Split(",")
            For ArrayY = 0 To num_cols
                strArray(ArrayX, ArrayY) = strline(ArrayY)
            Next
        Next


    End If
    Return strArray



End Function

When the value stored in the array, an error occurs saying the value isn't in the bounds of the array. When I inserted a break in the code where the array is supposed to increase in size, it said the value of strArray was only 1.

What is wrong with my code?

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
  • How is `strArray` declared? What do you mean with "the value of `strArray` was only 1"? Do you mean its size? What values do `num_rows` and `num_cols` have? Do they match the file's contents? – Nico Schertler Jun 07 '14 at 08:21
  • possible duplicate of [Reading CSV file and storing values in to an array](http://stackoverflow.com/questions/5282999/reading-csv-file-and-storing-values-in-to-an-array) – Ňɏssa Pøngjǣrdenlarp Jun 08 '14 at 13:29

0 Answers0