繁体   English   中英

.dat文件中的Visual Basic 2d数组

[英]Visual Basic 2d array from .dat file

所以我试图从两个文本文件中提取一些数据。 第一个加载并完美填充列表框。 第二个文本文件是我遇到麻烦的地方。 我似乎无法正确加载它。 我正在尝试将其放入2D数组MileageAr。 该消息框用于解决它是否正确加载到阵列中的问题。 我究竟做错了什么?

来自SDMileage.dat的样本数据

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

末级

Dim Mileage As New System.IO.StreamReader("SDMileage.dat")
Dim strLine As String
Dim strSplit() As String

将此更改为Mileage.Peek

Do While State.Peek <> -1
    strLine = Mileage.ReadLine
    strSplit = strLine.Split(",")

尝试以这种方式循环

Dim Mileage As System.IO.TextReader = New StreamReader("SDMileaage.dat")

do while ((strline = Mileage.ReadLine) <> nothing)

Peek方法可能很好,我在处理文本文件时通常只使用上面的代码,可能值得一试...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM