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?