PDA

Click to See Complete Forum and Search --> : How do I avoid using delay loops??


altosax
Jun 5th, 1999, 01:11 AM
Okay, this is a really basic question. I'm trying to do some animations using the Line method, drawing directly onto forms. To slow things down I've been calling delay loops from inside the main procedure. But this essentially locks up the computer for the duration of the animation. I've thought of putting the whole main procedure inside a timer control event procedure, but that seems unweildy. How do you get the computer to wait around while still being responsive to user input?
Thanks, altosax.

Drinky
Jun 5th, 1999, 05:25 AM
use the DoEvents command to make the app responsive during a loop

eg:
[code]
do until 1 = 2
DoEvents
loop
[/quote]

I'm not sure how to delay things however...

------------------
Second year Software Engineering Student looking for a placement
drinky.u4l.com (http://drinky.u4l.com)
wizard_03@hotmail.com

[This message has been edited by Drinky (edited 06-05-99).]

[This message has been edited by Drinky (edited 06-05-99).]

DVint
Jun 5th, 1999, 06:59 AM
Timers! Instead of loops, write your repeating code in timer controls, and set the intervals as you need. The interval increments are milliseconds, so if you set a timer's interval to 1000, it will execute once a second. At an interval of 100, it will execute 10 times a second. By experimenting you can find what are the realistic limits of a timer in a given program. At around 40 or so, you'll notice any further decrease in the interval property doesn't produce any faster executions, because the computer is now executing as fast as it can. (This all depends on what else your app is doing, and what else you have loaded in memory too.)

I've come to look at timers the way I used to think of For Next loops. All you have to remember is that execution will be moving in and out of the code you write in the timer, so be sure and make any variables that increment and/or keep track of things static. Also, if you want to be able to affect what a timer's code does from outside of it, you need to use form or module-level variables that are changed by actions from other controls such as slider bars, texts boxes, or whatever.

Last but not least, there are no theoretical limits to the number of timers you can put in a program. Recently I wrote a program that graphically simulates the functions of a water heater, and I put about 20 timers in that thing.

------------------

altosax
Jun 8th, 1999, 05:46 AM
Actually I have been using timers for some simple programming tasks. But certain things bother me. For example, if I am in one timer event procedure, how do I get something to happen every fourth timer event, but only for a while. I can't "call" a timer event sub. Yet I don't want it to constantly be doing this temporary thing.
Thanks.
Altosax