发布网友 发布时间:2022-05-06 13:28
共3个回答
热心网友 时间:2022-06-30 18:17
Private Sub Command1_Click()
热心网友 时间:2022-06-30 18:17
12345678910111213141516171819Private Sub Command1_Click() Dim i As Long, n As Long, y As Long, x As Long, a() As Integer y = List1.ListCount n = Val(Text1.Text) '获取输入的数量,text1可以自己改 If n < 1 Then Exit Sub '输入数量不能为0 If y < n Then Exit Sub '抽取数量不能为大于已经存在姓名列表 Randomize For i = 0 To n - 1 x = Int((y - 1 + 1) * Rnd + 1) '随生成机数字 ReDim Preserve a(i) a(i) = x For j = 0 To UBound(a) - 1 If x = a(j) Then i = i - 1: Exit For '判断是否重复 Next Next For i = 0 To UBound(a) List2.AddItem List1.List(a(i)) 'list1内抽取到的添加到list2,右边的 list1 和 list2 自己改 NextEnd Sub热心网友 时间:2022-06-30 18:17
先判断已经抽取的结果,如果存在重新抽取。追问能写出代码吗