vb 两个数组相加,把值赋予第三个数组Private Sub Command1_Click()Dim i As IntegerDim a(),b(),c()a() = Array(2,8,7,6,4,28,70,25)b() = Array(79,27,32,41,57,66,78,80)For i = 0 To 7c(i) = a(i) + b(i)Next iPrint c(i);End Sub我的程序如上,
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/08 14:50:55
vb 两个数组相加,把值赋予第三个数组Private Sub Command1_Click()Dim i As IntegerDim a(),b(),c()a() = Array(2,8,7,6,4,28,70,25)b() = Array(79,27,32,41,57,66,78,80)For i = 0 To 7c(i) = a(i) + b(i)Next iPrint c(i);End Sub我的程序如上,
vb 两个数组相加,把值赋予第三个数组
Private Sub Command1_Click()
Dim i As Integer
Dim a(),b(),c()
a() = Array(2,8,7,6,4,28,70,25)
b() = Array(79,27,32,41,57,66,78,80)
For i = 0 To 7
c(i) = a(i) + b(i)
Next i
Print c(i);
End Sub
我的程序如上,为什么总说“c(i) = a(i) + b(i)”越界呢?
Form1.AutoRedraw = True 请问这句话是什么作用?
vb 两个数组相加,把值赋予第三个数组Private Sub Command1_Click()Dim i As IntegerDim a(),b(),c()a() = Array(2,8,7,6,4,28,70,25)b() = Array(79,27,32,41,57,66,78,80)For i = 0 To 7c(i) = a(i) + b(i)Next iPrint c(i);End Sub我的程序如上,
我把你和程序修改了一下,你看看效果如何?
Private Sub Command1_Click()
Dim i As Integer
Form1.AutoRedraw = True
Dim a(),b(),c()
a() = Array(2,8,7,6,4,28,70,25)
b() = Array(79,27,32,41,57,66,78,80)
ReDim c(UBound(a()) + 1)
For i = 0 To 7
c(i) = a(i) + b(i)
Print c(i);
Next i
End Sub
现在来回答问题吧:
(1)Dim a(),b(),c()这样的声明语句没有真正规定数组的大小和上下标,所以还不能直接使用;
(2)一般再使用redim语句对它再进行定义,才能使用使用.本例中a()和b()都使用array()函数进行了隐性定义,所以能够使用了;
(3)而c()没有经过任何定义,所以,不能够给它赋值.程序中出现了出错的提示;
(4)我修改的程序重点是加上了redim语句.还有一点其它的调整.
有什么不明白,请留言.
补充:那一句的作用是让数据在窗口上能显示出来.