我写的这个程序下标越界了,应该怎么改?
PrivateSubForm_Load()Dimaa=Array(1,2,3,4,5,6,7)Fori=LBound(a)ToUBound(a)a(i)=a(i)*a(i...
Private Sub Form_Load()
Dim a
a = Array(1, 2, 3, 4, 5, 6, 7)
For i = LBound(a) To UBound(a)
a(i) = a(i) * a(i)
Next i
Print a(i)
End Sub 展开
Dim a
a = Array(1, 2, 3, 4, 5, 6, 7)
For i = LBound(a) To UBound(a)
a(i) = a(i) * a(i)
Next i
Print a(i)
End Sub 展开
2个回答
展开全部
改成这样就可以了:
Private Sub Form_Load()
Dim a
a = Array(1, 2, 3, 4, 5, 6, 7)
For i = LBound(a) To UBound(a)
a(i) = a(i) * a(i)
Next i
Print a(UBound(a))
End Sub
Private Sub Form_Load()
Dim a
a = Array(1, 2, 3, 4, 5, 6, 7)
For i = LBound(a) To UBound(a)
a(i) = a(i) * a(i)
Next i
Print a(UBound(a))
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很明显把i改成i-1
追问
是把Print 的那个i 改成i-1么?什么意思啊?谢谢!
追答
虽然我不是学VB的,但是很明显 For i = LBound(a) To UBound(a)你的这个语句取得的是数组的长度,而数组下标是从0开始的,所以 a(i) = a(i) * a(i)你的这个语句是下标越界的,应该改为: a(i-1) = a(i-1) * a(i-1)而且Print a(i)这个应该改为Print a(i-1)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询