-
In my program I have some calls that when I put message box between them (i was just debugging) it works fine. Without the message box it screws up. I tried using a Delay instead the code for my delay is
Code:
Private Sub Delay(ByVal pt As Integer)
Dim pausetime, Start
pausetime = pt ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + pausetime
DoEvents ' Yield to other processes.
Loop
End Sub
However, this doesn't solve the problem. I've even tried setting the integer value for the delay to a longer time, but that doesn't help either. How can I affect the program the way the message box does so the I can be sure my program works correctly?
-
First timer is very inaccurate, up to 53 ms, so use gettickcount api that is accurate up to 1 ms. Secondly pt is a integer, which causes you can only specify seconds. Pass pt as a long specifying amount of milliseconds instead of seconds:
Code:
Declare Function GetTickCount Lib "kernel32" () As Long
Sub Delay(ByVal pt As Long)
Dim t As Long
t = GetTickCount + pt
Do
DoEvents
Loop Until t < GetTickCount
End Sub
-
Don't put the DoEvent's in there, DoEvent's only concern's your app, Other applications will get proccessor Time Even if you put Your Code in a loop Without DoEvents
-
Will the looping even allow other parts of the program to process? I thought DoEvents allowed the events to finish processing before beginning the next step. They've served to help me prevent a call to an object before another event was finished with it.
Does affecting the time even help?