Hi.

I have a procedure that have been working good for years now. Why change it you might say? Well I wanted to make sure it's optimized (I doubt it is). I know there are real optimization gurus here so I'm giving it a try.

Sometimes I want my application to take a 'pause', to wait for some stuff to process, or a webpage to load (YES, even tho the browser has functions for this). Here is my code:

Usage:
Code:
Call proWait(10) '10 seconds
Procedure:
Code:
Public Sub proWait(WaitTimeInThousands As Long)
    '################################################
    'USING THE 'tmrWait' timer
    '################################################
    iWaitLoopCount = 0
    
    frmForm.tmrWait.Interval = WaitTimeInThousands
    frmForm.WaitTimerEnded = False
    frmForm.tmrWait.Enabled = True
    
    Do While frmForm.WaitTimerEnded = False
        iWaitLoopCount = iWaitLoopCount + 1
        If iWaitLoopCount = 40000 Then
            iWaitLoopCount = 0
            DoEvents
        End If
    Loop
    'DoEvents
End Sub
Code:
Private Sub tmrWait_Timer()
    WaitTimerEnded = True
End Sub
I had some 'remmed' lines in this code that I did not paste here, which were using the 'sleep' function. I don't know why I didn't use that - I guess I might have had problem in the past using it. It might be a good idea to try to use it? I guess that using 'sleep' was preventing my app, or browser, or whatever on it, to keep on running properly, hence rendering useless the use of sleep since nothing would process meanwhile.

In clear, I need a nice little function that would take a pause.

You might notice the 'iWaitLoopCount' loop in my code. I agree - this is weird. I think that without that loop, my whole procedure was too much of a resource hogger. And it seemed to work good with that loop inside the loop. I think this was used to avoid calling 'DoEvents' too often.

One suggestion might be to simply wait for 'Private Sub tmrWait_Timer' to trigger and act at that point, eliminating the need of a loop, but I need my code to keep executing from where the 'proWait' procedure was called...

Any comments grealy appreciated.

Thanks.