Reputation: 11
I am developping bingo application in powerpoint with a sound (bingo draw) connected to a object in the ppt. The bingo randomizer is also connected to the same object, and therefore, the random number generator has to pause for 7 sec until the sounds has played. Unfortunately my code with pause does not show a new generated number anymore while without the pause it works. So it works if i exclude the:
Application.Wait Now + TimeValue("0:00:07")
From:
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. if someone knows how to change the random generator to draw non-duplicates that would be a great addition
Upvotes: 1
Views: 2175
Reputation: 4913
Try a DoEvents loop instead. Place this declaration at the top of the module:
Public Declare PtrSafe Function GetTickCount Lib "kernel32.dll" () As LongPtr
Then add this sub:
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
Then replace the Wait statement with something like this:
Pause(10)
Upvotes: 1