|
-
Dec 4th, 2000, 05:55 PM
#1
Thread Starter
Member
I have a loop going. But between each loop I want it to wait 5 seconds. How would I do that? (before it goes on to loop again it has to wait 5 seconds)
-
Dec 4th, 2000, 06:01 PM
#2
Hyperactive Member
Code:
Public Function DelayLoop()
Dim intDelay As Integer ' Delay in seconds
Dim dtmTime As Date
Dim i As Integer
intDelay = 5
For i = 1 To 10
' Do your stuff here
Beep
dtmTime = Now()
Do Until DateDiff("s", dtmTime, Now()) >= intDelay
DoEvents
Loop
Next
End Function
-
Dec 5th, 2000, 03:11 AM
#3
Fanatic Member
API
You can use the API call Sleep
General Declarations
Code:
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Implementation
Code:
Sleep 5000 ' Wait 5 seconds
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Dec 5th, 2000, 04:44 AM
#4
PowerPoster
If you're doing some loop function, you should not applied the Sleep API function call. Because it will cause your entire application fall in idle mode.
So, you should use the GetTickCount API function call.
Code:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Form_Load()
Dim i As Integer
Do While i <> 100
i = i + 1
DELAY 5000
DoEvents
Loop
End Sub
Private Sub DELAY(ByVal interval As Long)
Dim t1 As Long
Dim t2 As Long
t1 = GetTickCount
t2 = 0
While t2 - t1 < inteval
t2 = GetTickCount
DoEvents
Wend
End Sub
-
Dec 5th, 2000, 04:52 AM
#5
Fanatic Member
???
Chris,
What is idle mode and what are the disadvantages of your program 'falling' into it??
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Dec 5th, 2000, 05:03 AM
#6
PowerPoster
Hi! YoungBuck, Idle mode mean the application will stop process any window message. That mean, the application will only resume all the on queue window message after the sleep interval.
Whereas, if you use another Do...Loop with GetTickCount API function, the application will be able to continue process the window message. As a result the user can close the application by click on the "X" button at anytime he/she wish.
-
Dec 5th, 2000, 05:43 AM
#7
Fanatic Member
Cool I didn't know that had a name for that
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Dec 5th, 2000, 06:34 PM
#8
Thread Starter
Member
don't worry you guys, I did it a totally different way. I didn't use any of your ideas. I actually found out how to use the timer and loop together. When the button is clicked, it calls another Private Function which enables the timer. After the timer is enabled it waits 5 seconds then it does everything and disables itself and then jumps to the Private Function. which I used an if statement, so if the conditions are right it will enabled the timer. Kind of complicated but it works. If you have any more questions you could email me [email protected]
--------------------------------------------------------
=-> Hot2fire <-=
http://ksearch.cjb.net - Search with results
-
Dec 5th, 2000, 11:39 PM
#9
Frenzied Member
Timers aren't good if your program is large. The timers start to get inacurate. By the way, Fox will yell at you if he finds you using them he hates timers and picture boxes.
Try to stay away from timers as much as possible. GetTickCount is more acurate anyway. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|