VBA-powerpoint中的计时器延迟

问题描述 投票:0回答:1

我正在用与ppt中的对象连接的声音(宾果游戏)在powerpoint中开发bingo应用程序。宾果游戏随机化器也连接到同一对象,因此,随机数生成器必须暂停7秒钟,直到声音播放完毕。不幸的是,我的具有暂停功能的代码不再显示新生成的数字,而没有暂停功能就可以了。因此,如果我排除:

Application.Wait Now + TimeValue("0:00:07")

发件人:

Sub UpdateRandomNumber(oSh As Shape)
Dim X As Long
'Make the shape’s text a random number
'X or less
'Change 50 below to any number you’d like:
X = 50


oSh.TextFrame.TextRange.Text = CStr(Random(X))
Application.Wait Now + TimeValue("0:00:07")
'Now force PPT to go to the slide again (ie, to redraw it) so that
'the changed text appears:
SlideShowWindows(1).View.GotoSlide (SlideShowWindows(1).View.Slide.SlideIndex)

End Sub

Function Random(High As Long) As Long

'Function Random(InArray() As Variant) 'new
'Generates a random number less than or equal to
'the value passed in High
Randomize
Random = Int((High * Rnd) + 1)

End Function

ps。如果有人知道如何更改随机生成器以绘制非重复项,那将是一个很好的补充

bingo in ptt

object powerpoint-vba pause
1个回答
0
投票

尝试使用DoEvents循环。将此声明放在模块顶部:

Public Declare PtrSafe Function GetTickCount Lib "kernel32.dll" () As LongPtr

然后添加此子:

Sub Pause(Length As LongPtr)
    Dim NowTime As LongPtr
    Dim EndTime As LongPtr

    EndTime = GetTickCount + (Length * 1000)
    Do
        NowTime = GetTickCount
        DoEvents
    Loop Until NowTime >= EndTime
End Sub

然后用以下内容替换Wait语句:

Pause(10)
© www.soinside.com 2019 - 2024. All rights reserved.