我要做的是获取CSV文件并将其导入数组。然后访问稍后在等式中使用的数据。
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
当存储在数组中的值时,会发生错误,指出该值不在数组的范围内。当我在代码中插入一个中断,其中数组的大小应该增加时,它表示strArray
的值仅为1.
我的代码出了什么问题?