Sub Test()
Dim bDic As New Dictionary, i As Integer
For i = 1 To 19
bDic(CStr(i)) = i
Next
For i = 33 To 35
bDic(CStr(i)) = i
Next
Randomize
Do While bDic.Count > 0
i = Int(Rnd * bDic.Count) ''隨機取一個
Debug.Print bDic.Keys(i)
bDic.Remove bDic.Keys(i) ''用過了就洗掉
Loop
End Sub
...
uj5u.com熱心網友回復:
試著用了一下,報錯“用戶型別未定義”,請問是什么愿意啊?
uj5u.com熱心網友回復:
Dim arr(9), k, r
Private Sub Command1_Click()
If Command1.Caption = "停止" Then Command1.Caption = "抽出" Else Command1.Caption = "停止"
If arr(0) = 0 Then
For i = 0 To 9
arr(i) = i + 1
Next
' MsgBox "10個初始化完成"
End If
Randomize
While Command1.Caption = "停止"
r = Int(Rnd * (10 - k)) + k
If Rnd > 0.2 Then
TextBox1.Text = "000"
Else
TextBox1.Text = Right("00" & arr(r), 3)
End If
DoEvents
Wend
If Command1.Caption = "抽出" Then
t = arr(r): arr(r) = arr(k): arr(k) = t: k = k + 1
TextBox1.Text = Right("00" & t, 3)
End If
If k > 9 Then
If Command1.Caption <> "抽出" Then k = 0
Command1.Caption = Join(arr, "-") & vbLf & "已全抽出,下一輪"
Else
Command1.Caption = Left(Join(arr, "-"), k * 2) & vbLf & "已抽第 " & k & " 個,下一個"
End If
End Sub
Sub OnSlideShowPageChange()
Command1.Caption = "開始"
打開.Caption = "打開"
TextBox1.Text = "000"
End Sub
Private Sub 打開_Click()
ActivePresentation.SlideShowWindow.View.GotoSlide (TextBox1.Text + 1)
End Sub
Private Sub Command1_Click()
Dim s$, v, i%, rndIndex%
'將要處理的資料處理放到陣列v
For i = 1 To 19
s = s & i & " "
Next
For i = 33 To 35
s = s & i & " "
Next
v = Split(Trim(s), " ")
Randomize
For i = 0 To UBound(v)
rndIndex = Int(Rnd * (UBound(v) - i))
Debug.Print i & vbTab & "隨機結果:" & v(rndIndex) & vbTab & "對應當前索引:" & rndIndex
v(rndIndex) = v(UBound(v) - i) '將回圈范圍的末資料拿到隨機的索引位置
Next
End Sub
Public Function GetRnd(Optional ByVal DataList As String = "") As String
Static Data() As String, Index As Integer
Dim I As Integer, J As Integer, S As String
If Len(DataList) > 0 Then
Randomize
Index = 0
Data = Split(DataList, ",")
For I = 0 To UBound(Data)
J = Rnd * (UBound(Data) + 1)
S = Data(I)
Data(I) = Data(J)
Data(J) = S
Next
End If
GetRnd = Data(Index)
Index = (Index + 1) Mod (UBound(Data) + 1)
End Function
Sub Test()
Dim bDic As New Dictionary, i As Integer
For i = 1 To 19
bDic(CStr(i)) = i
Next
For i = 33 To 35
bDic(CStr(i)) = i
Next
Randomize
Do While bDic.Count > 0
i = Int(Rnd * bDic.Count) ''隨機取一個
Debug.Print bDic.Keys(i)
bDic.Remove bDic.Keys(i) ''用過了就洗掉
Loop
End Sub