Results 1 to 11 of 11

Thread: [VB6/VBA] Timer class.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,780

    [VB6/VBA] Timer class.

    Hello everyone!

    This class allows to use the timers in VB6/VBA. It contains the Interval propertiy which sets the interval between the Tick events. It also contains the Tag property which allows to hold any data associated with the timer instance. The class uses the assembly thunks which check allow use the single class without any other dependencies. It also has the simple checking to reduce the crashes. It check the EbMode function and if the code is stopped it automatically disables the timers and if the code is in the stepping mode it just bypasses the events generation until the code is running. This checking simplifies debugging but doesn't exclude the crashes (because if the timer wasn't disabled since the last debugging session it'll continue execution with the old invalid data.) This code is compatible with the 64 bit office as well. If you want to add a method to the class you should update the TIMERPROC_INDEX constant according to the offset.

    Link on GitHub.

    Thanks for your attention!

    The trick, 2019.

  2. #2
    Hyperactive Member
    Join Date
    Aug 2016
    Posts
    510

    Re: [VB6/VBA] Timer class.

    Very useful

  3. #3
    Addicted Member
    Join Date
    Jun 2016
    Location
    Espaņa
    Posts
    244

    Re: [VB6/VBA] Timer class.

    great job

  4. #4
    Addicted Member
    Join Date
    Jan 2015
    Posts
    246

    Re: [VB6/VBA] Timer class.

    all ways dumplicated post, sorry

  5. #5
    Addicted Member
    Join Date
    Jan 2015
    Posts
    246

    Resolved Re: [VB6/VBA] Timer class.

    Quote Originally Posted by xxdoc123 View Post
    Very useful
    there has one uses paul caton's thunk in excelhome

  6. #6

  7. #7
    Addicted Member
    Join Date
    Jan 2015
    Posts
    246

    Re: [VB6/VBA] Timer class.

    when i say excelhome, i mean a forum
    http://club.excelhome.net/thread-629386-1-1.html this used Paul Caton's thunk in class
    but it can not be used in office x64

  8. #8
    Addicted Member
    Join Date
    Jan 2015
    Posts
    246

    Re: [VB6/VBA] Timer class.

    i can not use it in my office 2010 x86
    i add to ActiveX Control to main document, and write down code in "ThisDocument":
    when i click "Start" button, it debug nothing...
    Code:
    Option Explicit
    Private WithEvents c As CTrickTimer
    Private n As Long
    Private Sub c_Tick()
        n = n + 1
        Debug.Print c.Tag & vbTab & n
    End Sub
    Private Sub cmdStart_Click()
        Set c = New CTrickTimer
        c.Tag = "loquat"
        c.Interval = 1000
    End Sub
    Private Sub cmdStop_Click()
        c.Interval = 0
    End Sub

  9. #9

  10. #10
    Addicted Member
    Join Date
    Feb 2015
    Location
    Colorado USA
    Posts
    180

    Re: [VB6/VBA] Timer class.

    Trick,

    Great code! I do a lot of VBA coding and this is the first code that I have seen with a thunk that works in a 64-bit environment.

    I'd like to learn more about the thunks you have written (I used to do assembly programming many moons ago). Do you have the asm listing for the 32 and 64-bit thunks?

    You say we should change the TIMERPROC_INDEX constant, currently set to 5, that should be changed if the position of the function TimerProc changes. When I count procedures from the top, TimerProc is the 6th (the ones above it are properties) and counting from the bottom it is the 9th (8th for VBA).

    I am guessing the count is from the top but there is an issue (I think). For the Tag property there is a Let and a Set. I haven't seen this before. I am guessing that only one is used and if so then TimerProc is the 5th procedure. Is this correct? Which one can I delete?

    A minor nitpick: in a few places you use a conditional compilation constant expression "If CBool(VBA6 or VBA7)". Conditional compilation constants are boolean so the CBool is not required. Also, all code that has VBA7 et True also has VBA6 set True so you only need "If VBA6".

  11. #11
    Addicted Member
    Join Date
    Feb 2015
    Location
    Colorado USA
    Posts
    180

    Re: [VB6/VBA] Timer class.

    I took your VBA code and implemented it in Excel. I am now running it in 64-bit Office 365. I have noticed a strange thing. When I call up frmMain as a vbModal form everything woks as expected. However, if I open the form modelessly the timer never triggers. That doesn't make sense to me since all the form does relative to the timer(s) is to just catch the output in the ListBox. I can't see why the timer itself doesn't appear to fire.

Tags for this Thread

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