How to subtract numbers in labels using macros?

Hi,

I need help with simple macro, I have two slides on which I have labels with the number 20th I need a macro to me every second subtracted from the number one 20 and two on the slides will also be deducted. Subtraction results in the number 0
So every second of the two slides reduced by one digit, then after 20 seconds is to 0. The revised figures must always show the field value in the label.
Thank you in advance for your help, I attach the sample.

Regards,

TM
test20.ppt
Thomas_MeyerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris BottomleySoftware Quality Lead EngineerCommented:
Not sure I follow ...

20s is displayed on two slides ... do you want them both updating at the same time as counts from 20 to 0 decrementing every second?

i.e. whenever you transit to slide two it will show the same decrementing time?

Chris
TommySzalapskiCommented:
If this was Excel or Word, you could just use the Application.OnTime function. Since this is Powerpoint (with its limited VBA), it's a bit more complex.
Fortunately, you are not the only one who wants to do this. Pptfaq (which is an excellent resource for neat ppt stuff) has a list of methods you can pick from that should do what you are after: http://www.pptfaq.com/FAQ00081.htm
Thomas_MeyerAuthor Commented:
@Chris
Yes, exactly.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Chris BottomleySoftware Quality Lead EngineerCommented:
Haven't figured out a way to do the timer myself as yet, but maybe someone will come up with a specific soon.

Of course if buying an add-in is a possibility (http://www.tushar-mehta.com/powerpoint/ppt_timer/index.htm) then  maybe that will lead to a solution BUT do not buy it as yet ... I will need to do myself first to see if it can be used ... and how.

Chris
Thomas_MeyerAuthor Commented:
@Chris
Yeah, but I is really a very primitive macro that will symbolize the countdown. In essence, solves the problem of how to always make a 1-second pause between the time and then subtracting that time appeared on both labels.
Chris BottomleySoftware Quality Lead EngineerCommented:
Last time I tried such I crashed PPT ... but I am still a learner on PPT.

How complicated will the presentation become?

Chris
Thomas_MeyerAuthor Commented:
It is a simple presentation. A simple deduction can be done easily using animation, but I do not know the way after running out of time animations automatically run a macro? The best way might be to program the entire animation via VBA, but it will be difficult.
TommySzalapskiCommented:
You could just put
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
at the top of a module to use the Sleep API. Sleep 1000 will sleep for one second (it's in milliseconds).
TommySzalapskiCommented:
Ack, sleep is no good because it's a spin lock so you can't do anything while it's sleeping. Use this code. I tested it and it's working great for me. Note: The code must be in a module not Slide1.
I'll also post my working example. Currently, you need to start the presentation and click on one of the labels to start the timer. If you want the timer to fire when you start the presentation, then you'll probably need an add-in to handle the events.
Option Explicit

Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, _
                                        ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private TimerID As Long

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Dim objExcel As Excel.Application
Dim i As Integer
Public Sub RunTimer()
i = 20
Slide1.Label1.Caption = i
Slide2.Label1.Caption = i
TimerID = SetTimer(0, 0, 1000, AddressOf Decrement)
End Sub

Public Sub Decrement()
KillTimer 0, TimerID
i = i - 1
Slide1.Label1.Caption = i
Slide2.Label1.Caption = i
If i > 0 Then
  TimerID = SetTimer(0, 0, 1000, AddressOf Decrement)
Else
  'Timer has expired. Add custom code here
End If
End Sub

Open in new window

test20.ppt

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Thomas_MeyerAuthor Commented:
I just needed, thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.