怎么在vb的列表框中随机输出n个一维数组
PrivateSubCommand2_Click()Dima()AsInteger,nAsInteger,iAsIntegeri=Val(InputBox("输入数组个数...
Private Sub Command2_Click()
Dim a() As Integer, n As Integer, i As Integer
i = Val(InputBox("输入数组个数"))
Randomize
For i = 1 To n
a(i) = Int(90 * Rnd) + 10
Next i
List1.AddItem a(i)
End Sub
但它说下标越界怎么回事啊,求回复啊。。。。万分感激 展开
Dim a() As Integer, n As Integer, i As Integer
i = Val(InputBox("输入数组个数"))
Randomize
For i = 1 To n
a(i) = Int(90 * Rnd) + 10
Next i
List1.AddItem a(i)
End Sub
但它说下标越界怎么回事啊,求回复啊。。。。万分感激 展开
4个回答
展开全部
我修改了一下,应该是你想要的效果。出错的原因是因为你的n是没有赋值的。
Private Sub Command2_Click()
Dim n As Integer, i As Integer
Dim a() As Integer
i = Val(InputBox("输入数组个数"))
ReDim a(i) As Integer
Randomize
For n = 0 To i - 1
a(n) = Int(90 * Rnd) + 10
List1.AddItem a(n)
Next n
End Sub
Private Sub Command2_Click()
Dim n As Integer, i As Integer
Dim a() As Integer
i = Val(InputBox("输入数组个数"))
ReDim a(i) As Integer
Randomize
For n = 0 To i - 1
a(n) = Int(90 * Rnd) + 10
List1.AddItem a(n)
Next n
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command2_Click()
Dim a() As Integer, n As Integer, i As Integer
n= Val(InputBox("输入数组个数"))
Randomize
For i = 1 To n
a(i) = Int(90 * Rnd) + 10
List1.AddItem a(i)
Next i
End Sub
Dim a() As Integer, n As Integer, i As Integer
n= Val(InputBox("输入数组个数"))
Randomize
For i = 1 To n
a(i) = Int(90 * Rnd) + 10
List1.AddItem a(i)
Next i
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以试一下我这种
Private Sub Command2_Click()
Dim n As Integer, i As Integer
Dim a() As Integer
n= Val(InputBox("输入数组个数"))
ReDim a(1 to n) As Integer
Randomize
For i = 1 to n
a(I) = Int(90 * Rnd) + 10
List1.AddItem a(i )
Next i
End Sub
Private Sub Command2_Click()
Dim n As Integer, i As Integer
Dim a() As Integer
n= Val(InputBox("输入数组个数"))
ReDim a(1 to n) As Integer
Randomize
For i = 1 to n
a(I) = Int(90 * Rnd) + 10
List1.AddItem a(i )
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询