From: Dee Earley on
On 03/03/2010 23:51, Jim Mack wrote:
> You could wait in a 'loose' DoEvents loop, using Sleep or PeekMessage
> within it. Inside the loop, check the status of the form you opened,
> and exit when it's no longer active.
>
> A sneaky way to do that might be:
>
> Do
> Sleep 50
> Loop While DoEvents> 1

Wow, I never knew it returned anything...
I assume the return value is just forms.count as well, but seems a bit
of an odd thing to return...

--
Dee Earley (dee.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems
From: Jim Mack on
Dee Earley wrote:
> On 03/03/2010 23:51, Jim Mack wrote:
>> You could wait in a 'loose' DoEvents loop, using Sleep or
>> PeekMessage within it. Inside the loop, check the status of the
>> form you opened, and exit when it's no longer active.
>>
>> A sneaky way to do that might be:
>>
>> Do
>> Sleep 50
>> Loop While DoEvents> 1
>
> Wow, I never knew it returned anything...
> I assume the return value is just forms.count as well, but seems a
> bit of an odd thing to return...


It seems to be fairly obscure, I agree.

I've used this when I have a project that runs as a timer-based state
machine inside Sub Main.

Create a form instance, then enter a loop containing the state
machine:

Sub Main

Dim frmX as Form1

frmX.Load

' setup code here

frmX.Show

Do While DoEvents
' complex state tree here..
Sleep x
Loop

' cleanup code here

End Sub

Then when the form closes, things shut down naturally. It nicely
separates the actual logic from the UI.

--
Jim Mack
Twisted tees at http://www.cafepress.com/2050inc
"We sew confusion"

From: Karl E. Peterson on
Paul Clement wrote:
> BTW, if I remember correctly I believe that DoEvents makes a call to Sleep
> with a value of 0 (giving up the app's time slice).

I think that's true, but a tight DoEvents loop will still appear to
consume 100% cpu. That's the utility of the brief call to Sleep,
directly. Gives the user the correct impression of resource usage,
should they be monitoring that.

--
..NET: It's About Trust!
http://vfred.mvps.org