Link to home
Start Free TrialLog in
Avatar of babygirls
babygirls

asked on

Timer

Dearest Expert,

nw, i have to Run a program which is...
1. after retrieved everything frm database, then i have to stop for a mayb 5seconds and continue my whole process again.means start retrieve for data again.

(run my process ---> Stop for 5 second ---->run process again.)

so may i knw hw to write it?

thanks.
Avatar of lyonst
lyonst
Flag of Ireland image

Try this,

Any time the behavior of your code depends on the Timer function you should take into account the (more or less) remote possibility that your code is executed just before midnight. Take for example the following code:


Sub Pause(seconds as Single)
    Dim initTime as Single
    initTime = Timer
    Do: Loop Until Timer >= initTime + seconds
End Sub

http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=292

Cheers,

T.
ASKER CERTIFIED SOLUTION
Avatar of lyonst
lyonst
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If Ur Process can take more than 5 sec


May Be U  must take care of Multi call of procedure

( I mean U may need to cancel one process Old or new )

This may be done By static variable (NoOfProcRunning)

U may Increment it on proc. start then decrement it at end

Thus U can use it inside Ur multi line process to control it


I hope that helps

'use a timer control on a vb form.

Option Explicit

Private Sub Form_Load()
Timer1.Interval = 5000
End Sub

Private Sub Timer1_Timer()

'your database code called from here

End Sub
Avatar of smkkaleem
smkkaleem

Try the following:

(run my process --->

'Stop for 5 seconds
Wait 5

---->run process again.)


Public Sub Wait(Seconds)
    Dim X, Y

    X = Now
    Do Until Now > (X + ((Seconds / 60) * 0.0007))
        Y= "aaaaa"
    Loop
   
End Sub

Avatar of Éric Moreau
You can use this API:

Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

And you use it:
Call Sleep(5000)
I am with emoreau.
emoreau and Richie Simonetti.

I already mentioned sleep - please see my comment above ?? !!

Here it is again just in case you missed it

or >>>>

Using Sleep function example

http://www.mvps.org/vbnet/index.html?code/helpers/splash.htm

Cheers,

T.
iyonst...

emoreau missed that part of your comment and showed the code-only answer.

richie just prefers raw code answers over link-pasting.
iyonst..., sorry CareyJ is right.

CareyJ, i don't prefer any of them. I would like to see links when we didn't write the code and code posted when we wrote it and don't found somewhere else.
Cheers
The SLEEP API call is much better than the timer loops resource wise... I think that would be your better choice.