Link to home
Start Free TrialLog in
Avatar of n96radsb
n96radsb

asked on

Loop troubles

I have problems with loops...

I have a program that read pixels from another application. That works fine so far.
Depending on what happens in the other application I want do things in my own program.
If for example some pixels in the other application become blue I want to increment an integer in my program. basically just monitor what happens in another application.

I was thinking about using a loop. and in the loop have calls to functions and subs. In the example below status and analyze

Private Sub runLoop()
While (True)
   DoEvents
   Sleep (500)
   statusText.Text = status
   analyze
Wend
end sub

This doesnt work very good, my computer becomes unstable after awhile and I have to restart visual basic.

What is a good solution for this. I want to be able to control the speed of the loop, so that it calls the functions and subs like twice every second.

thanks in advance

//Björn
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America 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
>I want to increment an integer in my program
If you do use the Timer event, make sure you declare your integer as a global variable, so that it keeps its value between timer events.
Avatar of n96radsb
n96radsb

ASKER

okay thanks jim

it seems to be working fine so far. I'll give you your points later tonight, just in case some problems come up with the timers... =)
Okay.  Keep in mind that with a Timer control, if you have a TimerInterval = 500 (half a second), that translates to 'the timer event will fire sometime after the system clock is a half a second past', and not exactly a half a second.