如何在VBA PowerPoint中生成随机的一对唯一图像
如果我想创建一个随机订单以从图像中选择另一对。 ,不要重复我以前选择的随机对,即,一旦经过56个随机唯一图像即26个随机对,游戏就结束了,并重置为我的原始57张图像,然后再次选择随机对。可以在VBA PowerPoint中完成吗?
这是我正在使用的子:
Sub RandomImage()
Dim i As Long
Dim posLeft As Long
For i = 1 To 2
Randomize
RanNum% = Int(57 * Rnd) + 1
Path$ = ActivePresentation.Path
FullFileName$ = Path$ + "/" + CStr(RanNum%) + ".png"
posLeft = 50 + ((i - 1) * 400)
Call ActivePresentation.Slides(1).Shapes.AddPicture(FileName:=FullFileName$, LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=posLeft, Top:=100, Width:=400)
Next
End Sub
If I want to create a random order to select another pair from my image. , not repeating the random pair i've previously picked, i.e. so that once i've gone through 56 random unique images i.e. 26 random pairs, the game is over, and reset to my original 57 images and start picking random pairs again. Can this be done in VBA Powerpoint?
This is the sub I am using:
Sub RandomImage()
Dim i As Long
Dim posLeft As Long
For i = 1 To 2
Randomize
RanNum% = Int(57 * Rnd) + 1
Path$ = ActivePresentation.Path
FullFileName$ = Path$ + "/" + CStr(RanNum%) + ".png"
posLeft = 50 + ((i - 1) * 400)
Call ActivePresentation.Slides(1).Shapes.AddPicture(FileName:=FullFileName$, LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=posLeft, Top:=100, Width:=400)
Next
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请尝试下一个功能。它使用从1到最大必要/现有数字构建的数组。它返回
rnd
数组元素,然后将其从数组中消除,下次从剩余的元素中返回:到达限制并发送消息时,使用的数组将重置。
它可以使用下一个测试
sub
进行测试:为了更快地测试,您可以修改
MAXNO
20 ...在测试它后,您必须修改代码下一个方式:
请测试并发送一些反馈。我没有在访问中测试它,但应该可以工作...
Please, try the next function. It uses an array built from 1 to maximum necessary/existing number. It returns the
RND
array element and then eliminate it from the array, next time returning from the remained elements:The used array is reset when reaches its limit and send a message.
It may be tested using the next testing
Sub
:In order to test it faster, you may modify
maxNo
at 20...After testing it, you have to modify your code in the next way:
Please, test it and send some feedback. I did not test it in Access, but it should work...