所以我試圖從兩個文本文件中提取一些數據。第一次加載並完美地填充列表框。第二個文本文件是我遇到麻煩的地方。我似乎無法正確加載它。我正在嘗試將其放入二維數組MileageAr中。如果消息框正確加載到陣列中,則該消息框將進行故障排除。我究竟做錯了什麼?從SDMileage.dat來自.dat文件的Visual Basic 2d數組
1,54,465,58,488,484
5,54,654,87,841,844
等
示例數據....
Public Class ArrayFun
Dim MileageAr(10, 10) As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim State As New System.IO.StreamReader("SDCities.dat")
Dim strState As String
Dim i, j As Integer
Do While State.Peek <> -1
strState = State.ReadLine
lstFrom.Items.Add(strState)
lstTo.Items.Add(strState)
Loop
Dim Mileage As New System.IO.StreamReader("SDMileage.dat")
Dim strLine As String
Dim strSplit() As String
Do While State.Peek <> -1
strLine = Mileage.ReadLine
strSplit = strLine.Split(",")
j = 0
For Each miles In strSplit
MileageAr(i, j) = miles
j += 1
Next
i += 1
Loop
State.Close()
Mileage.Close()
End Sub
Private Sub lstTo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstTo.SelectedIndexChanged
MsgBox(MileageAr(1, 1))
End Sub
末級
它拋出一個錯誤? – adatapost