Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

infinite loop for active x executable 1

Status
Not open for further replies.

Painkiller

Programmer
May 18, 2001
97
NL
Hi all,

I need to make an active x executable that runs an infintate loop, executing tasks when documents are found in a directory. My question is, how do I create an infinte loop? I thought about using do-loop stastements without the while, something like this:

do

[actions]

loop

Would this work? Suggestions?

Thankx,

Sujesh
 
Yes, a Do loop would be one way of doing it. You'd implement it like this:
[tt]
Do Until False
' Your code goes here
Loop
[/tt]
Some thoughts, though. A tight loop like this is a processor hog, and performance of any other applications running on your machine won't get a look in. Your occassionally needs to yield control. You can do this with a DoEvents command. So The routine might now look something like:
[tt]
Do Until False
' Your code goes here
DoEvents ' yield control here
Loop
[/tt]

However, use of DoEvents should be judicious (there can sometimes be some unexpected side-effects of its use), so you might only want to yield control say every 100 or 1000 times through the loop, which you can control with some sort of counter, as follows:
[tt]
Dim lCounter as long
lCounter=0
Do Until False
' Your code goes here
lCounter=(lCounter + 1) Mod 100
If lCounter = 0 Then DoEvents
Loop
[/tt]
Having said all this, I only like using DoEvents where absolutely neccessary. So you might want to consider an alternative approach to what you are doing. Perhaps you could put your code into a timer event instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top