Repeat function using Timer is getting stuck in a loop before repeating in VBA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Using a previous solution on this forum as a reference: https://forums.autodesk.com/t5/vba/re-repeat-function-in-autocad-vba/m-p/10618756/highlight/false#M1... I am using a modification of this code to call an external function every 5 seconds.
It runs normally for the most part, but for reasons unknown to me, the code can get stuck looping between the 3 lines :
"Do While Timer < start + PAUSE
DoEvents
Loop"
I've tried breaking the code execution and going into the debugger, to find that the "start" value can mysteriously be much bigger than "Timer", even though start is re-declared in every iteration of the loop before going into the while loop above.
Even more confusing is that without restarting the code entirely, I can run the code line by line using F8, and it will magically fix itself and break out of this loop.
Can someone provide more insight into why and how this problem arises, and any possible solutions?
Thank you.
Best Regards,
Ryan
Option Explicit
Private Const PAUSE As Integer = 5 '' Seconds for Timer to pause
Private Const INTERVAL As Integer = 5 '' 30 seconds
Private startTime As Date
Private start As Long
Public Sub DoWork()
Dim go As Boolean
Dim currentTime As Date
Dim timeDiff As Long
startTime = Now
Do
go = True
start = Timer
Do While Timer < start + PAUSE
DoEvents
Loop
Dim i As Long
Call Run_Report
If New_Item < 1 Then
'MsgBox "No new jobs"
GoTo skip:
End If
Call delete_all
Call runsql
' If i = New_Item - 1 Then
' End
' End If
skip:
Loop While go
'MsgBox "Repeating work has been cancelled!"
End Sub