OfficeTips Home || VBA Section || General Section || Download Section || Privacy Policy |
Simulate a countdown timer using Sleep API |
|
This example simulates a countdown and then jumps on to the second slide. It makes use of the Sleep API to suspend the macro execution for an interval of 1 second. To run this example , Insert two autoshapes onto the 1st slide. Set the action settings of the 2nd autoshape to run macro Tmr. Start the show, the click click on the autoshape, it runs the Tmr Macro which simulates the countdown (interval specified) and upon completion moves on to the next slide Note: In the Slide Transition Window of the Slide, which contains the "timer" textbox, both the Advance options have been unchecked. This prevents the slide from advancing due to an accidental mouse click ' --------------------------------------------------------------------------------
Option Explicit Sub Tmr()
'Just in the eventuality that you click the start button twice
Static isRunning As Boolean 'On Slide 1, Shape 1 is the textbox
With ActivePresentation.Slides(1) 'Countdown in seconds
TMinus = 120 ' Suspend program execution for 1 second (1000 milliseconds) Sleep 1000
xtime
= Now TMinus = TMinus - 1 ' Very crucial else the display won't refresh itself
DoEvents ' 3-2-1-0 Blast off and move to the next slide or any slide for that matter
SlideShowWindows(1).View.GotoSlide (2) End Sub
|
|
Using SetTimer/KillTimer API in PowerPoint 2000 |
|
PowerPoint 2000 supports the new AddressOf keyword. This lets you call a specific Windows API function in your code and pass to it the address of a procedure in your project that you want that API function to call. This keyword allows us to make calls to a whole range of API calls which were otherwise unusable. Care should be taken that your VBA routine is so designed to receive exactly the same type and number of arguments as the API function expects to send to it. If not you can be sure that a lot of GPF's and hair pulling will follow. So lets learn how to make use of the AddressOf while calling the SetTimer API. The SetTimer API let's us specify the time interval and we need to specify the procedure to be invoked when the time interval has elapsed. We do so using the AddressOf operator. TimerProc is the procedure that we desire to invoke after 1 second has elapsed hence the statement.
KillTimer API is used to terminate the Timer using the TimerID obtained while creating the timer using SetTimer call. '
-------------------------------------------------------------------------------- Option Explicit 'API Declarations Declare Function SetTimer Lib
"user32" _ Declare Function KillTimer Lib
"user32" _
' Public Variables Public SecondCtr As Integer Sub TimerOnOff() If bTimerState = False Then
' The defined routine gets called every nnnn milliseconds. Sub TimerProc(ByVal hwnd As Long, _ End Sub
|
Copyright 1999-2022 (c) Shyam Pillai. All rights reserved.