waitTime = 3
Start = Timer
While Timer < Start + waitTime
DoEvents
Wend
Function Wait(Seconds As Double) As Boolean
Static StartTime As Double If StartTime = 0 Then StartTime = Timer
If Timer - StartTime >= Seconds Then
Wait = True StartTime = 0
End If
End Function
The problem with these functions is that they literally pause the whole Power Point Presentation(I want Animations to keep playing while the macro does it's job.), and since I'm making a Power Point Game, I don't want it to do that because it messes with the experience and the flow of the Game.Sub GameLoop()
SlideShowWindows(1).View.GotoSlide (X) Waitfor 3
If SlideShowWindows(1).View.CurrentShowPosition = X Then
SlideShowWindows(1).View.GotoSlide (Y)
Else
End If
End Sub
By the way I found useful information in the matter, although I'm not sure on how to implement those to my own functions or macros, its complicated. I will leave reference links:Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal TimerID As Long, ByVal Delay As Long, ByVal CallBackFunction As LongPtr) As Long
Private Declare PtrSafe Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal TimerID As Long) As Long
#Else
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal TimerID As Long, ByVal Delay As Long, ByVal CallBackFunction As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal TimerID As Long) As Long
#End If
Private mDelay As Long
Private mTimerID As Long
Private mCallBackFunction As LongPtr
Friend Sub Construct(ByVal Delay As Long, CallBackFunction As LongPtr)
mDelay = Delay
mCallBackFunction = CallBackFunction
End Sub
Public Sub Start()
If (mTimerID = 0) Then
mTimerID = SetTimer(0, 0, mDelay, mCallBackFunction)
If mTimerID = 0 Then
Err.Raise Err.LastDllError, "Timer", "Failed to start the timer."
Exit Sub
End If
End If
End Sub
Public Sub Kill()
If (mTimerID <> 0) Then
mTimerID = KillTimer(0, mTimerID)
If mTimerID = 0 Then
mTimerID = 0
Err.Raise Err.LastDllError, "Timer", "Failed to stop the timer."
Exit Sub
End If
mTimerID = 0
End If
End Sub
The Timer class only have 2 member functions:Option Explicit
Public Function Create_Timer(ByVal Delay As Long, ByVal CallBackFunction As LongPtr) As Timer
Set Create_Timer = New Timer
Create_Timer.Construct Delay, CallBackFunction
End Function
You will call Create_Timer to instanciate a Timer object.Option Explicit
Private Timer As Timer
Public Sub test()
Set Timer = TimerFactory.Create_Timer(5000, AddressOf onTime)
Debug.Print Now
Timer.Start
End Sub
Private Sub onTime()
Debug.Print "Timer fired at: " & Now
Timer.Kill
End Sub
Note that the Timer instance need a module scope.
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Then call it with this statement in your code:Sleep 1000
The number after Sleep is milliseconds, so this offers fine control.
Public Function Actual() As Integer
Actual = SlideShowWindows(1).View.CurrentShowPosition
End Function
Option Explicit
Private Timer As Timer
Public Sub test()
Set Timer = TimerFactory.Create_Timer(2000, AddressOf onTime)
Debug.Print Now
MsgBox ("Start")
Timer.Start
End Sub
Private Sub onTime()
If Actual = 2 Then
Debug.Print "Timer fired at: " & Now
MsgBox ("Finished")
Timer.Kill
Else
Debug.Print "Timer fired at: " & Now
MsgBox ("You're not in the first Slide")
Timer.Kill
End If
End Sub
Public Sub TestLoop()
Set Timer = TimerFactory.Create_Timer(3000, AddressOf onTime)
Debug.Print Now
SlideShowWindows(1).View.GotoSlide (8)
Timer.Start
End Sub
Option Explicit
Private Timer As Timer1
Public Sub test1()
Set Timer = TimerFactory.Create_Timer(3000, AddressOf onTime)
Debug.Print Now
MsgBox ("Start_1")
Timer.Start
End Sub
Private Sub onTime1()
If Actual = 1 Then
Debug.Print "Timer fired at: " & Now
MsgBox ("Finished_1")
Timer.Kill1
Else
Debug.Print "Timer fired at: " & Now
MsgBox ("You're not in the first Slide_1")
Timer.Kill1
End If
End Sub
It has been years since I last used one, but it worked as follows
1. the user started a macDoIt macro that processed thousands of database updates.
2. The macDoIt started by opening a "Modeless" user form named "frmMonitorProgress"
3. Since frmMonitorProgress was modeless is ran concurrently with macDoIt,
Once every minute frmMonitorProgress would update a form text box.
the form looked something like this
Records Processed 1 through 553
Process paused at record 553
Click here to Pause processing.
Click here to restart processing.
Click here to unload the form and cancel further processing.
If you think something like that would work for you I could dig up the code.