7,785
社区成员




Private Sub Command1_Click()
Randomize
List2.Clear
For i = 0 To List1.ListCount - 1
b = Int(Rnd * (List1.ListCount))
List2.AddItem List1.List(b)
List1.RemoveItem b
List1.Refresh
Next i
For i = 0 To List2.ListCount - 1
List1.AddItem List2.List(i)
Next i
Print List1.ListCount
End Sub
Private Sub Form_Load()
For i = 0 To 99
List1.AddItem i
Next i
List2.Visible = False
Command1.Caption = "打乱顺序"
End Sub
Dim i As Integer '变量
Dim intTmp As Integer '临时变量
Dim subject_id() As Integer '题目编号
Dim subject_name() As Integer '题目标题
Dim intCount As Integer '题目数量
Dim intNum As Integer '要出的题目数量
intNum = 20 '初始化出20道题
Set rs = getRS("select subject_ID,subject_name from subject where 条件")
intCount = rs.recordcount
ReDim subject_id(intCount) As Integer
ReDim subject_name(intCount) As Integer
For i = 0 To intCount - 1
subject_id(i) = rs("subject_id")
subject_name(i) = rs("subject_name")
rs.movenext
Next
rs.Close
If intCount < intNum Then
MsgBox "题目不够!"
End If
'至此,符合条件的题目已经放到数组中了
'出20道不重复的题
For i = 1 To intNum
Randomize Timer
intTmp = Int(Rnd() * intCount)
Debug.Print (subject_id(intTmp) & ":" & subject_name(intTmp))
'每出一道题后,把数组题题后一道题换掉已出题目,数组大小减1,再出后面的题才不会重重
intCount = intCount - 1
subject_id(intTmp) = subject_id(intCount)
subject_name(intTmp) = subject_name(intCount)
ReDim Preserve subject_id(intCount) As Integer
ReDim Preserve subject_name(intCount) As Integer
Next