Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 来自.dat文件的Visual Basic二维数组_.net_Vb.net_Visual Studio 2010 - Fatal编程技术网

.net 来自.dat文件的Visual Basic二维数组

.net 来自.dat文件的Visual Basic二维数组,.net,vb.net,visual-studio-2010,.net,Vb.net,Visual Studio 2010,所以我试图从两个文本文件中提取一些数据。第一种方法完美地加载和填充列表框。第二个文本文件是我遇到问题的地方。我似乎无法正确加载它。我想把它放到一个二维阵列里,米耳。messagebox用于诊断是否正确加载到阵列中。我做错了什么 SDMiledge.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_

所以我试图从两个文本文件中提取一些数据。第一种方法完美地加载和填充列表框。第二个文本文件是我遇到问题的地方。我似乎无法正确加载它。我想把它放到一个二维阵列里,米耳。messagebox用于诊断是否正确加载到阵列中。我做错了什么

SDMiledge.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
公共类ArrayFun
昏暗的里程(10,10)作为字符串
私有子表单1_Load(ByVal发送方作为System.Object,ByVal e作为System.EventArgs)处理MyBase.Load
Dim状态为新System.IO.StreamReader(“SDCities.dat”)
作为字符串的Dim strState
作为整数的Dim i,j
边说边做
strState=State.ReadLine
lstFrom.Items.Add(strState)
lstTo.Items.Add(strState)
环
将里程变暗为新System.IO.StreamReader(“SDMiles.dat”)
暗斯特林作为弦
Dim strSplit()作为字符串
边说边做
strLine=里程数.ReadLine
strSplit=strLine.Split(“,”)
j=0
在strSplit中每英里
里程(i,j)=英里
j+=1
下一个
i+=1
环
State.Close()
里程数。关闭()
端接头
私有子lstTo_SelectedIndexChanged(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理lstTo.SelectedIndexChanged
MsgBox(里程数(1,1))
端接头
末级

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(",")
Do While State.Peek-1
strLine=里程数.ReadLine
strSplit=strLine.Split(“,”)
尝试以这种方式循环

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

do while ((strline = Mileage.ReadLine) <> nothing)
Dim里程作为System.IO.TextReader=新的StreamReader(“SDMileaage.dat”)
do while((strline=里程数.ReadLine)nothing)
Peek方法可能很好,我只是在处理文本文件时通常使用上面的代码,可能值得一试

将此更改为里程数。查看

Do While State.Peek <> -1
    strLine = Mileage.ReadLine
    strSplit = strLine.Split(",")
Do While State.Peek-1
strLine=里程数.ReadLine
strSplit=strLine.Split(“,”)
尝试以这种方式循环

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

do while ((strline = Mileage.ReadLine) <> nothing)
Dim里程作为System.IO.TextReader=新的StreamReader(“SDMileaage.dat”)
do while((strline=里程数.ReadLine)nothing)

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

它会抛出错误吗?它会抛出错误吗?没有错误,我只是无法从数组中获得任何输出,这意味着它没有正确填充。您可以在分配到数组之前在行上设置断点并检查值,然后单步执行,查看数组是否填充?代码看起来不错,所以我不确定当您尝试使用数组时问题是否没有。因此,一步一步地阅读文本文件的第一行很好,我可以输出它,但此文件中有不止一行。谢谢Sparky的帮助。我做错了的是,我没有将数组调整到足够大的大小,这就是为什么。有没有方法可以自动调整数组的大小?没有错误,我只是无法从数组中获得任何输出,这意味着数组没有正确填充。您可以在数组赋值之前在行上设置断点并检查值,然后单步执行,查看数组是否填充?代码看起来不错,所以我不确定当您尝试使用数组时问题是否没有。因此,一步一步地阅读文本文件的第一行很好,我可以输出它,但此文件中有不止一行。谢谢Sparky的帮助。我做错了的是,我没有将数组调整到足够大的大小,这就是为什么。有没有办法自动调整阵列的大小?