我在PowerPoint VBA上做了一个单词抽奖,但我想知道如何使随机不重复,并可能在所有单词都被使用时停止?从那以后谢谢你,我想把所有的功劳都给那个宏的创建者。
我使用的代码
Dim x As New Collection
Sub box()
Dim items() As String
Dim y As Long
items = Split("Blinding\ Nightmare\ Ice cream\", "\")
For y = 0 To UBound(items)
x.Add (items(y))
Next y
End Sub
Sub wordspick()
Dim words As Long
Randomize
y = Int(Rnd * x.Count) + 1
Shapes("x").TextFrame.TextRange.Text = x(y)
x.Remove (y)
End Sub发布于 2021-03-29 14:24:36
Dim x As Collection
Sub box()
Dim items() As String
Dim y As Long
Set x = New Collection 'clear x, in case not empty
items = Split("Blinding\Nightmare\Ice cream", "\")
For y = 0 To UBound(items)
x.Add items(y)
Next y
Randomize
End Sub
Sub wordspick()
Dim words As Long, y As Long
If Not x Is Nothing Then 'check collection is initialized
If x.Count = 0 Then
Debug.Print "No more words!" 'collection is empty
Else
y = Int(Rnd * x.Count) + 1
'Shapes("x").TextFrame.TextRange.Text = x(y)
Debug.Print x(y)
x.Remove y
End If
End If
End Subhttps://stackoverflow.com/questions/66843526
复制相似问题