From: Bee on
I have seen this talked about but still not sure which is the correct way to
do this.
Either way below seems to work.

A form is opened for the user to click on something.
The form is modless. It cannot be modal.

I want other events in the app (timer driven) and outside the app to have
max process time while the user is thinking.

so, do I use Sleep or a system timer or ...?

Do
DoEvents
Sleep 200&
Loop While bLoop

or

Do
DoEvents
WaitMS 200&
Loop While bLoop

The user clicking a button changes the state of bLoop to False.

WaitMS is a
CreateWaitableTimer
subroutine

Or if there is a better way, what is it?

From: Karl E. Peterson on
Bee wrote:
> I have seen this talked about but still not sure which is the correct way to
> do this.

Do what, exactly? Won't the form just wait all by itself?

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


From: Helmut Meukel on

"Bee" <Bee(a)discussions.microsoft.com> schrieb im Newsbeitrag
news:82E48F11-2E53-43EF-B50E-E4DAB216F438(a)microsoft.com...
>I have seen this talked about but still not sure which is the correct way to
> do this.
> Either way below seems to work.
>
> A form is opened for the user to click on something.
> The form is modless. It cannot be modal.
>
> I want other events in the app (timer driven) and outside the app to have
> max process time while the user is thinking.
>
> so, do I use Sleep or a system timer or ...?
>
> Do
> DoEvents
> Sleep 200&
> Loop While bLoop
>
> or
>
> Do
> DoEvents
> WaitMS 200&
> Loop While bLoop
>
> The user clicking a button changes the state of bLoop to False.
>
> WaitMS is a
> CreateWaitableTimer
> subroutine
>
> Or if there is a better way, what is it?
>

Hi Bee,

I don't think there is THE correct way to wait.
It depends on the circumstances.

First, if your app waits for user interaction, don't
use any loop at all. Check it with an test app
-compiled- with a textbox and a command button.
Open taskmanager and look at cpu usage of your
test app while sitting there and waiting for the user.
IMHO there is nothing you must do to minimize
cpu usage.
If I transfer some data to a plc in a machine, I have
to poll the the plc to retieve the return values.
There I use a loop with DoEvents and Sleep, but
the value for Sleep I use is only 100 ms.

HTH,

Helmut.

From: Bee on
I do not want the calling form code to proceed until the user makes a choice
on frmX.
I do not want a modal form using vbModal because I cannot get past other
issues using a vbModal form.

frmX.Show ' this opens the form
' after the frmX _Load event execution continues here.
' but I do not want it to be until the user makes a choice.

So I put the loop in frmX to wait there until the choice is made.

What way would you implement this?




"Karl E. Peterson" wrote:

> Bee wrote:
> > I have seen this talked about but still not sure which is the correct way to
> > do this.
>
> Do what, exactly? Won't the form just wait all by itself?
>
> --
> ..NET: It's About Trust!
> http://vfred.mvps.org
>
>
> .
>
From: Karl E. Peterson on
Bee wrote:
> I do not want the calling form code to proceed until the user makes a choice
> on frmX.
> I do not want a modal form using vbModal because I cannot get past other
> issues using a vbModal form.

Ahhhhh! I see. You want to "wait" the calling form.

> frmX.Show ' this opens the form
> ' after the frmX _Load event execution continues here.
> ' but I do not want it to be until the user makes a choice.
>
> So I put the loop in frmX to wait there until the choice is made.
>
> What way would you implement this?

I'd loop while the called form is visible, then query it's properties
(though which you'd return the result code[s]), and destroy it.

Something like:

frmX.Show
Do While frmX.Visible
DoEvents '<- only if needed, try without first
Sleep 20
Loop
Result = frmX.CustomResultCode
Set frmX = Nothing

Make sense?

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