When setting a Timer using the API func. SetTimer,
How can you make sure that the handle of the timer you're
providing isn't already in use?
Is there a function that returns the next valid timer handle?
Something like FreeFile???

Thanks in advance
Who is Participating?

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

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.

The SetTimer API function creates a timer, the return value is a long integer identifying the new timer.  It is unique.

There is a Timer control with VB - it's easier to use.

If the return value is zero, the function failed.
BabyFaceAuthor Commented:

Perhapse I should make my question a little clearer.

This is the definition of SetTimer:
Declare Function SetTimer Lib "user32" Alias "SetTimer" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

How do I find the next valid timer identifier?
because what if you did this?
SetTimer me.hwnd,1,1000,addressof Myfunc
[in another function]
SetTimer me.hwnd,1,1000,addressof MyFunc2
[destory event]
KillTimer 1
???? What about the other timer?????
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!

As I said, the timer function RETURNS a long integer identifying the new timer. It is unique.  When set the timer like this:

TimerID = SetTimer me.hwnd,1,1000,addressof Myfunc

And release it:

Kill TimerID

The second argument in you're example (1) is the EVENT ID

BabyFaceAuthor Commented:
TimerID = SetTimer me.hwnd,1,1000,addressof Myfunc
And release it:
Kill TimerID

I suppose you ment KillTimer TimerID right?
But the description of the KillTimer say that it receives a windows hwnd  and the timer identifier
not the timer handle.
So how do you find the next valid timer handle.?

Well, if you look at the SetTimer description - you'll find the following:

Return Values
If the function succeeds, the return value is an integer identifying the new timer. An application can pass this value, or the string identifier, if it exists, to the KillTimer function to destroy the timer. If the function fails to create a timer, the return value is zero.

The syntax for releasing the timer would therefore be:

KillTimer hWnd, TimerID

What makes the TimerID unique is the hWnd.  You must specify a different ID if you're going to create a second timer using the same hWnd.  In your example, 1000 would be the only timer associated with me.hwnd.


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
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.