On Sunday, December 30, 2001, at 03:36 PM, Kevin Ballard wrote:
On 12/30/01 3:29 PM, "Charles Yeomans" <yeomans at desuetude dot com> wrote:
Yes it does. WindowCount = 0 precisely when there are no windows open.
So the While loop executes if and only if there are windows open.
Yeah, but if a window refuses to close, then the loop will execute
forever.
Bad idea.
Okay, since you brought it up, here's how you reliably handle this
problem. The problem is this: you'd like to loop through all open
windows and close them. One way to do this is to include a sentinel in
the loop to guard against infinite loops. For instance:
dim loopSentinel as Integer
loopSentinel = 0 //yes, I know RB initializes variables; I'm making it
explicit for readability
While (WindowCount > 0) and (loopSentinel < WindowCount)
Window(0).Close
loopSentinel = loopSentinel + 1
Wend
I know that loopSentinel increases each iteration, and WindowCount never
increases. Thus I can be certain that this loop will terminate, and in
fact I know that the loop will terminate in at most WindowCount
iterations.
But note that this technique can fail, I think, in a multithreaded
app -- using globals in a multithreaded app requires special care.
Charles Yeomans
|