VB 实时错误:'5' 如何解决?
1个回答
展开全部
改为
If List1.ListIndex >= 0 Then List1.RemoveItem List1.ListIndex
If List1.ListIndex >= 0 Then List1.RemoveItem List1.ListIndex
更多追问追答
追问
我想实现从列表框随机抽取1-24个数字,抽取显示后,列表框内该数字删除,然后继续从剩下的数字里面抽,直到全部抽光
n = List1.ListCount
Randomize
For i = 1 To n
s = Int(Rnd * (n - 1 + 1)) + 1
List1.Text = s
Label3.Caption = List1.Text
Next i
追答
如果你的目的只是想获得一个1到24的不重复的随机序列,用不着搞这么复杂的,也用不着列表框来中转的,直接在数组中处理即可:
Dim a(1 To 24) As String
Dim i As Integer, j As Integer, k As String
Private Sub Form_Load()
Randomize
For i = 1 To 24
a(i) = i
Next i
For i = 1 To 24
j = Int(Rnd * 24) + 1
k = a(j)
a(j) = a(i)
a(i) = k
Next i
Label3.Caption = Join(a, " ")
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询