Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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 索引数小于索引数组的维数_.net_Arrays_Vb.net - Fatal编程技术网

.net 索引数小于索引数组的维数

.net 索引数小于索引数组的维数,.net,arrays,vb.net,.net,Arrays,Vb.net,我想读取文件并将行放入1d选项卡中,然后在另一个1d选项卡中拆分每行,然后将所有内容添加到2d选项卡中。但是我得到“索引的数量小于索引数组的维数”。我不明白:您对数组的赋值是错误的。这: Dim tableautemp() As String = IO.File.ReadAllLines(nomfichier) Dim etudianttemp() As String For i As Integer = 0 To tableautemp.Length - 1

我想读取文件并将行放入1d选项卡中,然后在另一个1d选项卡中拆分每行,然后将所有内容添加到2d选项卡中。但是我得到“索引的数量小于索引数组的维数”。我不明白:您对数组的赋值是错误的。这:

    Dim tableautemp() As String = IO.File.ReadAllLines(nomfichier)
    Dim etudianttemp() As String

    For i As Integer = 0 To tableautemp.Length - 1
        etudianttemp() = tableautemp(i).Split(";"c)
        For j As Integer = 0 To 6
            tableau(j, i) = etudianttemp(j)
        Next
    Next
应该是:

etudianttemp() = tableautemp(i).Split(";"c)

出现的错误是,您似乎试图分配给数组中的某个项,而不是数组本身,然后需要提供该项的索引。错误消息仅基于赋值的左侧错误这一事实,而不考虑右侧。

您对数组的赋值错误。这:

    Dim tableautemp() As String = IO.File.ReadAllLines(nomfichier)
    Dim etudianttemp() As String

    For i As Integer = 0 To tableautemp.Length - 1
        etudianttemp() = tableautemp(i).Split(";"c)
        For j As Integer = 0 To 6
            tableau(j, i) = etudianttemp(j)
        Next
    Next
应该是:

etudianttemp() = tableautemp(i).Split(";"c)

出现的错误是,您似乎试图分配给数组中的某个项,而不是数组本身,然后需要提供该项的索引。错误消息仅基于赋值的左侧错误这一事实,它没有考虑右侧。

删除
etudiantemp()=…
=>
etudiantemp=…
中的括号,如中所述(别忘了将他的答案标记为已接受)


我只想补充一点,在尝试使用
I
j
在循环中赋值之前,您应该初始化
tableau
数组大小。顺便说一下,如果您删除了代码中的一些行以本地化问题,只需放弃以下答案:)

如果没有固定大小的J维度,则应在运行时通过首先解析每个tableautemp(i)来设置tailleDimensionJ,只保留最大项数

    Dim tableautemp() As String = IO.File.ReadAllLines(nomfichier)
    Dim etudianttemp() As String
    Dim tailleDimensionJ As Int32 = 6 ' edit accordingly.. Caution: Base 0 => 7 items

    Redim tableau(tailleDimensionJ, tableautemp.length - 1) ' here !

    For i As Integer = 0 To tableautemp.Length - 1
        etudianttemp = tableautemp(i).Split(";"c)
        For j As Integer = 0 To tailleDimensionJ ' and here !
            tableau(j, i) = etudianttemp(j)
        Next
    Next
Dim tableautemp()作为字符串=IO.File.ReadAllLines(nomfichier)
Dim etudianttemp()作为字符串
尺寸尾部尺寸J为Int32=0
对于i作为整数=0到tableautemp.Length-1
etudianttemp=表格AUTEMP(i).拆分(“;”c)
如果尾部尺寸J<(etudianttemp.Length-1)
tailleDimensionJ=etudianttemp.长度-1
如果结束
下一个
Redim表格(尾部尺寸J,表格长度-1)
对于i作为整数=0到tableautemp.Length-1
etudianttemp=表格AUTEMP(i).拆分(“;”c)

如中所述,将j作为整数=0到etudianttemp.Length-1'删除
etudianttemp()=…
=>
etudianttemp=…
中的括号(别忘了将他的答案标记为已接受)


我只想补充一点,在尝试使用
I
j
在循环中赋值之前,您应该初始化
tableau
数组大小。顺便说一下,如果您删除了代码中的一些行以本地化问题,只需放弃以下答案:)

如果没有固定大小的J维度,则应在运行时通过首先解析每个tableautemp(i)来设置tailleDimensionJ,只保留最大项数

    Dim tableautemp() As String = IO.File.ReadAllLines(nomfichier)
    Dim etudianttemp() As String
    Dim tailleDimensionJ As Int32 = 6 ' edit accordingly.. Caution: Base 0 => 7 items

    Redim tableau(tailleDimensionJ, tableautemp.length - 1) ' here !

    For i As Integer = 0 To tableautemp.Length - 1
        etudianttemp = tableautemp(i).Split(";"c)
        For j As Integer = 0 To tailleDimensionJ ' and here !
            tableau(j, i) = etudianttemp(j)
        Next
    Next
Dim tableautemp()作为字符串=IO.File.ReadAllLines(nomfichier)
Dim etudianttemp()作为字符串
尺寸尾部尺寸J为Int32=0
对于i作为整数=0到tableautemp.Length-1
etudianttemp=表格AUTEMP(i).拆分(“;”c)
如果尾部尺寸J<(etudianttemp.Length-1)
tailleDimensionJ=etudianttemp.长度-1
如果结束
下一个
Redim表格(尾部尺寸J,表格长度-1)
对于i作为整数=0到tableautemp.Length-1
etudianttemp=表格AUTEMP(i).拆分(“;”c)

对于j As Integer=0到etudianttemp.Length-1'的值,欢迎使用。另外,由于您是StackOverflow的新手,我想通知您,您可以通过勾选答案旁边的勾号来选择好答案并接受对您帮助最大的答案。在这个网站上,一个向上投票或一个被接受的答案都算作“谢谢”。欢迎你。另外,由于您是StackOverflow的新手,我想通知您,您可以通过勾选答案旁边的勾号来选择好答案并接受对您帮助最大的答案。在这个网站上,投票或被接受的回答都算作“谢谢”。