CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2000
    Location
    Midwest, USA
    Posts
    8

    Using a Timer in VBA

    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)?


    Security cannot be bought at the expense of civil liberties. Live free or die.

  2. #2
    Join Date
    Mar 2000
    Posts
    95

    Re: Using a Timer in VBA

    check out the timer control at

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

    Curt


  3. #3
    Join Date
    Mar 2000
    Location
    Midwest, USA
    Posts
    8

    Re: Using a Timer in VBA

    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?

    Security cannot be bought at the expense of civil liberties. Live free or die.

  4. #4
    Join Date
    Mar 2000
    Posts
    95

    Re: Using a Timer in VBA

    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


  5. #5
    Join Date
    Mar 2000
    Location
    Midwest, USA
    Posts
    8

    Re: Using a Timer in VBA

    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


    Security cannot be bought at the expense of civil liberties. Live free or die.

  6. #6
    Join Date
    Jul 2000
    Posts
    110

  7. #7
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Using a Timer in VBA

    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
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured