Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.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
Arrays 索引超出数组的界限_Arrays_Vb.net - Fatal编程技术网

Arrays 索引超出数组的界限

Arrays 索引超出数组的界限,arrays,vb.net,Arrays,Vb.net,也许我要问你的问题很琐碎,但是我已经检查了我所有的代码,我找不到错误在哪里。我使用下面的代码有两种不同的方法,通过组合框选择,来计算相同的变量。调试器正确启动,但在第九行我收到以下错误:System.IndexOutOfRangeException:“索引超出了数组的边界。” 以下是我正在使用的代码: Dim ts As Double Dim tsdim As Double Dim tsdom(tsdim) As Double Dim hrrspk(tsdim) As Double ts = C

也许我要问你的问题很琐碎,但是我已经检查了我所有的代码,我找不到错误在哪里。我使用下面的代码有两种不同的方法,通过组合框选择,来计算相同的变量。调试器正确启动,但在第九行我收到以下错误:
System.IndexOutOfRangeException:“索引超出了数组的边界。”
以下是我正在使用的代码:

Dim ts As Double
Dim tsdim As Double
Dim tsdom(tsdim) As Double
Dim hrrspk(tsdim) As Double
ts = CInt(Form3.TextBox5.Text) 
If Form3.ComboBox1.SelectedItem = "Automatic system" Then
    tsdim = ts + 1
    For i = 0 To ts
        tsdom(i) = i
        hrrspk(i) = Form3.ListBox2.Items(i)
    Next
    tsdom(tsdim) = ((CInt(Label6.Text) - ts) * (CInt(Label3.Text) - CInt(Label4.Text)) / CInt(Label6.Text)) + CInt(Label4.Text)
    hrrspk(tsdim) = 0
End If
If Form3.ComboBox1.SelectedItem = "Control system" Then
    tsdim = ts + 2
    For i = 0 To ts
        tsdom(i) = i
        hrrspk(i) = Form3.ListBox2.Items(i)
    Next
    tsdom(ts + 1) = Label4.Text
    tsdom(ts + 2) = Label3.Text
    hrrspk(ts + 1) = hrrspk(ts)
    hrrspk(ts + 2) = 0
End If

谢谢大家都会回答我的。致以最诚挚的问候。

您不能像这样声明数组:
Dim tsdim为Double Dim tsdom(tsdim)为Double
,并期望数组的大小根据
tsdim
的未来值进行更改。如果您事先不知道尺寸,请使用
列表(双倍)
并向其中添加项目。