0
我在我的代碼中收到索引錯誤,但我確信在我嘗試打印的位置內有數據。獲取「索引在數組的外部」錯誤但位置內有數據
下面是問題代碼。
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim seriesName As String = ComboBox2.SelectedItem.ToString()
Dim seriesLocation As String = "excelFiles/seriesID.csv"
Dim seriesData = File.ReadAllText(seriesLocation)
Dim seriesRows = Split(seriesData, vbCrLf)
For Each line In seriesRows
Dim seriesItem = Split(line, ",")
If seriesItem(1) = seriesName Then '<--- this is the error line
TextBox2.Text += seriesItem(2) + ","
End If
Next
End Sub
我已經使用了類似的子其中工程這個代碼,並在另一個訪問該文件,但我只是不明白爲什麼這不是在這一個工作。
我想使用組合框內的項目,並將其與存儲在數組中的CSV數據進行比較。
我在下面添加了一些圖片,顯示錯誤以及當我嘗試顯示位置時會發生什麼。
Difference in Printing Location "0" (top) and "1" (bottom)
唯一的區別是,我已經改變seriesItem(1)至seriesItem(0)
感謝您的幫助
'如果line.Contains(「,」)Then'您的圖像甚至顯示該行=「」。所以,沒有逗號。 – LarsTech
[爲什麼我的VB.NET數組有額外的值?](http://stackoverflow.com/questions/29840510/why-does-my-vb-net-array-have-extra-values) – GSerg
您的文件位置可能不在您認爲的位置。使用完整路徑。 – LarsTech