Click to See Complete Forum and Search --> : Using a Timer in VBA


MGlaenzer
August 1st, 2000, 11:49 AM
I want to use a timer in my VB code, but when I launch VB from an app (say, MSWord, for instance), the Timer control does not appear on my palette of available controls.

I tried adding a reference to IETimer (Tools/References), which worked on my machine. But other members of my programming team are unable to execute this code because the IETimer is unavailable on their machines (they have IE5, which apparently removed this control).

Is there a Timer control which can be referenced via VBA which I can confidently expect to be available on machines which will be executing this code (Win95, Win98, NT4, W2K)?

Curt
August 1st, 2000, 01:44 PM
check out the timer control at

http://www.mvps.org/ccrp/

Curt

MGlaenzer
August 1st, 2000, 02:41 PM
Curt,
Thanks for the link, but....

We need a timer control which we can confidently assume is ALREADY on our customer's computers (assuming they have VB6). Here's the situation: we have an EXE built with VC++ which contains VBA support. We would like to ship our product with a pre-built set of VBA macros and functions which our users can use as a starting point for writing more sophisticated extensions. Unfortunately, one of the pre-built functions we would like to provide must utilize a timer (I always thought the Timer object was native to VB, but I guess I was wrong). The High Performance Timer Object (your link) contains some nice extensions (no forms necessary!), but how can I use it in this context?

We would also like to write a tutorial describing how to perform certain functions with our software via VBA. How can we write these tutorials without knowing what controls are available to our customers? Should we redistribute the High Performance Timer Object with our app? Is it legal to do so?

Finally, does anyone have any idea as to WHY the timer control is available thru VB, but not VBA? Why isn't there a simple 1::1 correspondence between available controls in each context? Is there some technical reasoning as to why the default Timer control is not available in VBA?

Curt
August 1st, 2000, 02:59 PM
Try using these api functions



'function and type declarations

Declare Function timeGetDevCaps Lib _
"winmm.dll" (lpTimeCaps as _
TIMECAPS, byval uSize as Long) as Long
Declare Function timeBeginPeriod Lib _
"winmm.dll" (byval uPeriod as Long) as Long

Declare Function timeEndPeriod Lib _
"winmm.dll" (byval uPeriod as Long) as Long



Declare Function timeGetTime Lib "winmm.dll" () as Long


Declare Sub Sleep Lib "kernel32" (byval dwMilliseconds as Long)


Type TIMECAPS
lMinTimeLength as Long
lMaxTimeLength as Long
End Type

'in form

private Sub Command1_Click()
Dim tc as TIMECAPS
timeGetDevCaps tc, len(tc)

MsgBox tc.lMinTimeLength & " " & tc.lMaxTimeLength _
& " " & len(tc)

Dim mm1 as Long
Dim mm2 as Long
Dim mm3 as Long
Dim Period as Long

Period = 1

timeBeginPeriod Period
mm1 = timeGetTime()

Sleep (15) 'wait 15 mSec

mm2 = timeGetTime()
timeEndPeriod Period

mm3 = mm2 - mm1

MsgBox mm3
End Sub

private Sub Command2_Click()
Dim ans as Long

ans = timeGetTime()

MsgBox ans

End Sub





'hope this helps

Curt

MGlaenzer
August 1st, 2000, 03:56 PM
Curt,
Thanks, the provided code certainly helps! I am playing around with it in my VBA project. When (and if) I have any follow-up questions, I will post them in a new thread.

Thanks again,
Mark

Un1
February 20th, 2001, 03:57 AM
http://www.banasoft.com/DownLoad/BNTimer.exe

Clearcode
February 20th, 2001, 08:04 AM
There is an article describing how to use the Windows API to get around the need for a timer control here:
http://www.merrioncomputing.com/vb_subclass1.htm

HTH,
Duncan

-------------------------------------------------
Got "BigMetalHead"? You will soon
http://www.merrioncomputing.com