I want to execute specific chunks of code at specified intervals. I can do this with ONE chunk of code using the following from API-Guide:

VB Code:
  1. ' This project requires a Form and a Module
  2. ' The Form must have two command buttons (Command1
  3. '  and Command2) on it.
  4. '
  5. 'In a form
  6. Private Declare Function CreateTimerQueue Lib "kernel32.dll" () As Long
  7. Private Declare Function CreateTimerQueueTimer Lib "kernel32.dll" (ByRef phNewTimer As Long, ByVal TimerQueue As Long, ByVal Callback As Long, ByVal Parameter As Long, ByVal DueTime As Long, ByVal Period As Long, ByVal Flags As Long) As Long
  8. Private Declare Function DeleteTimerQueue Lib "kernel32.dll" (ByVal TimerQueue As Long) As Long
  9. Private Declare Function DeleteTimerQueueTimer Lib "kernel32.dll" (ByVal TimerQueue As Long, ByVal Timer As Long, ByVal CompletionEvent As Long) As Long
  10. Private hQueue As Long
  11. Private hTimer As Long
  12. Private Sub Form_Load()
  13.     'KPD-Team 2002
  14.     'URL: [url]http://www.allapi.net/[/url]
  15.     'E-Mail: [email][email protected][/email]
  16.     hQueue = CreateTimerQueue()
  17.     Command1.Caption = "Start"
  18.     Command2.Caption = "Stop"
  19. End Sub
  20. Private Sub Form_Unload(Cancel As Integer)
  21.     DeleteTimerQueue hQueue
  22. End Sub
  23. Private Sub Command1_Click()
  24.     If hTimer = 0 Then
  25.         CreateTimerQueueTimer hTimer, hQueue, AddressOf TimerCallBack, ByVal 0&, 0, 1000, 0
  26.     End If
  27. End Sub
  28. Private Sub Command2_Click()
  29.     If hTimer <> 0 Then
  30.         DeleteTimerQueueTimer hQueue, hTimer, ByVal 0&
  31.         hTimer = 0
  32.     End If
  33. End Sub
  34.  
  35. 'In a module
  36. Public Sub TimerCallBack(ByVal lpParameter As Long, ByVal TimerOrWaitFired As Long)
  37.     Debug.Print "Timer callback..."
  38. End Sub

My problem is i can't create more than one timer. Whenever i point CreateTimerQueueTimer to a Sub besides TimerCallBack, an error occurs.

Example: CreateTimerQueueTimer hTimer, hQueue, AddressOf MySub, ByVal 0&, 0, 1000, 0

How can I make that work?