|
先问候各位大佬元宵节快乐!本人菜鸟有一事相求!我从网上下了一个随机点名的ppt用于课堂教学,具体代码如下(本人对代码一窍不通)。但是用起来好像有些问题,说是随机,但重复率好像有些高,所以想请各位大佬帮忙看一下,能不能优化一下,使得随机但又不重复,有劳了!附上ppt文件
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim arrRM, F
Private Sub CommandButton1_Click()
If Me.CommandButton1.Caption = "停" Then
Me.CommandButton1.Caption = "开始"
Call CQ_do("stop")
Else
Me.CommandButton1.Caption = "停"
Call CQ_do("start")
End If
End Sub
Private Sub CQ_do(doTag)
If doTag = "start" Then
arrRM = Split(Me.TextBox1, ";", -1, 1)
F = 0
Do While True
Sleep 30
Dim i As Integer, j As Integer, a(0 To 1) As String
Randomize
For i = 0 To 1
1:
a(i) = Int((UBound(arrRM) + 1) * Rnd)
For j = i - 1 To 0 Step -1
If a(i) = a(j) Then
GoTo 1
End If
DoEvents
Next
Next
TextBox2.Text = arrRM(a(0))
If F = 1 Then Exit Do
DoEvents
Loop
Else
F = 1
End If
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox2_Change()
End Sub
|
|