Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 05-12-2004, 05:06 AM   #1 (permalink)
 
Newb Techie

Join Date: Mar 2004

Posts: 43

NCISAGENT

Question Timing Code

What code do you use to create a delay in the processing of the code

in other words....say you want to make a small amount of time to wait inside of a for loop each time it executes?
__________________
Awww **** it!!! My computer is on fire again
NCISAGENT is offline  
Old 05-12-2004, 10:13 AM   #2 (permalink)
 
Monster Techie

Join Date: Jul 2003

Posts: 1,179

Emily is on a distinguished road

Send a message via AIM to Emily
Default

This all depends on what language you're using. I do it highly inefficiently: I store the current system time in a variable. Then I add the time to it that I want it to loop for (say, 5 seconds). Then I do a while loop (while the system time is less than the variable that holds the altered time). Inside the loop, there's no code, but it'll still loop for 5 seconds.

I know there are much more efficient ways to do it (there are Timer APIs, I think), but that way has worked for me.
__________________
<a href=\"http://www.upstark.com\">www.upstark.com</a>
Emily is offline  
Old 05-13-2004, 07:13 AM   #3 (permalink)
 
Newb Techie

Join Date: Mar 2004

Posts: 43

NCISAGENT

Default

Im using C++ (Borland 6.0)

I want to have absolutly no processes from the program while the computer waits---I dont know if that is possible but what you have suggested seems to process empty code...right?

Also - Im not a C++ wizard .... but how do you grab the system time?
__________________
Awww **** it!!! My computer is on fire again
NCISAGENT is offline  
Old 05-24-2004, 09:09 PM   #4 (permalink)
 
Newb Techie

Join Date: Feb 2004

Posts: 8

lordjox

Default

I am using Borland 5.0 so this should work for you. windows.h has a function called Sleep(); which allows you to set a time, in milliseconds, to pause. For example, if you wanted your program to pause for 500 milisecs (half a second) you would type Sleep(500);
*note the 'S' in Sleep must be capitalized.
lordjox is offline  
Old 05-25-2004, 01:19 PM   #5 (permalink)
 
Newb Techie

Join Date: May 2004

Posts: 11

strange

Default

just to note sleep has a 5 minute limitation.
strange is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On