doevents 
Author Message
 doevents

Hello,

I am using a doevents command in a loop which continuously
draws on the screen, but after I started using doevents I
can't quit the form. Any ideas?



Sat, 10 Mar 2012 03:33:16 GMT  
 doevents


Quote:
> Hello,

> I am using a doevents command in a loop which continuously
> draws on the screen, but after I started using doevents I
> can't quit the form. Any ideas?

Use a flag to stop what the loop is doing. Example air code:

Private m_bStop As Boolean

Private Sub Form_Unload...
    m_bStop = True
End Sub

Private Sub Command1_Click()
    Do While True ' Infinite loop
        ' Some code
        DoEvents
        If m_bStop Then
            Exit Do
        End If
    Loop
End Sub



Sat, 10 Mar 2012 03:44:57 GMT  
 doevents

Quote:

> I am using a doevents command in a loop which continuously
> draws on the screen, but after I started using doevents I
> can't quit the form. Any ideas?

Please explain "quit the form" and "can't".
--
.NET: It's About Trust!
 http://vfred.mvps.org


Sat, 10 Mar 2012 03:46:06 GMT  
 doevents

Quote:

> > I am using a doevents command in a loop which continuously
> > draws on the screen, but after I started using doevents I
> > can't quit the form. Any ideas?

> Please explain "quit the form" and "can't".
> --
> .NET: It's About Trust!
> ?http://vfred.mvps.org

quit = when I press the little X in the top-right of the box, then the
program doesn't stop at all, it continues to draw on the screen.


Sat, 10 Mar 2012 04:05:42 GMT  
 doevents

Quote:


> > Hello,

> > I am using a doevents command in a loop which continuously
> > draws on the screen, but after I started using doevents I
> > can't quit the form. Any ideas?

> Use a flag to stop what the loop is doing. Example air code:

> Private m_bStop As Boolean

> Private Sub Form_Unload...
> ? ? m_bStop = True
> End Sub

> Private Sub Command1_Click()
> ? ? Do While True ' Infinite loop
> ? ? ? ? ' Some code
> ? ? ? ? DoEvents
> ? ? ? ? If m_bStop Then
> ? ? ? ? ? ? Exit Do
> ? ? ? ? End If
> ? ? Loop
> End Sub

but then I need to close the program twice?


Sat, 10 Mar 2012 04:15:09 GMT  
 doevents

Quote:
> the little X in the top-right of the box

For future reference, this is called the "close box."


Sat, 10 Mar 2012 04:14:30 GMT  
 doevents

Quote:
> Hello,

> I am using a doevents command in a loop which continuously
> draws on the screen, but after I started using doevents I
> can't quit the form. Any ideas?

I'v experienced the same thing, an stop as suggested is nice... an
global variable might be an idea if a private doesnt work, private...
whats the scope of that, not respondning out of control for a
private...
VB6 isnt multithread, nah, but then ...
it (the program/process) seems to avoid alt-F4, tried an exe... could
(sucessfully) stop it with killing the process though...
I sort of figured it was sort of calling it self before the doevents,
and then the "stop/pause in the IDE"  just killed the dead loop...
if it had killed the loop, then it should have stopped...
but not sort of hard:
In ide just hit (the buttons on the keyboard) break... or ctrl
break... shift break...  not working with IDE stop button as I
remember...

A while ago though... thought about installing that and adding it to
run or autostart to a few of my coworkers flew across my mind...
rotating the screen or something for 30 sek, or to make it funnt a
minute... but nah...

try searching for vb6 and fps, maybe timer or ms.. will get you a
better idea of how to do an animation... Just a thought..

Seen it (the strange{*filter*} on), never used it.. just as I said,
tried it.



Sat, 10 Mar 2012 04:24:59 GMT  
 doevents

Quote:



>> > I am using a doevents command in a loop which continuously
>> > draws on the screen, but after I started using doevents I
>> > can't quit the form. Any ideas?

>> Please explain "quit the form" and "can't".

> quit = when I press the little X in the top-right of the box, then the
> program doesn't stop at all, it continues to draw on the screen.

You need to add an exit clause to your loop, as "Nobody" suggests.

Otherwise, it'll do just what you coded it to do -- keep running.
--
.NET: It's About Trust!
 http://vfred.mvps.org



Sat, 10 Mar 2012 04:42:40 GMT  
 doevents

Quote:

>I am using a doevents command in a loop which continuously
>draws on the screen, but after I started using doevents I
>can't quit the form. Any ideas?

Someone else has answered the question, so I'll get all philosophical
on you: Using DoEvents in a loop like this is almost never the correct
solution.

Not doubt I'm in the minority, and I'm sure I've done it once or twice,
but I feel it's almost always better to break up whatever chunk of work
you're doing into more manageable pieces, and let the window procedure
process messages normally.

--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
   The beginning is the most important part of the work.
   -- The Republic by Plato



Sat, 10 Mar 2012 04:56:16 GMT  
 doevents

Quote:


>> Hello,

>> I am using a doevents command in a loop which continuously
>> draws on the screen, but after I started using doevents I
>> can't quit the form. Any ideas?

> I'v experienced the same thing, an stop as suggested is nice... an
> global variable might be an idea if a private doesnt work, private...
> whats the scope of that, not respondning out of control for a
> private...
> VB6 isnt multithread, nah, but then ...

Actually a running VB application is multi-threaded. At a minimum there is
the App thread and a current window (Form) thread. Else how would DoEvents
work?

VB apps are notoriously non-thread safe however. Perhaps that is what you
meant.

It looks what you are trying to do is cross-threading, which would have to
be managed differently than simply with a DoEvents.

-ralph



Sat, 10 Mar 2012 05:19:32 GMT  
 doevents

Quote:


>> I am using a doevents command in a loop which continuously
>> draws on the screen, but after I started using doevents I
>> can't quit the form. Any ideas?

> Someone else has answered the question, so I'll get all philosophical
> on you: Using DoEvents in a loop like this is almost never the correct
> solution.

> Not doubt I'm in the minority, and I'm sure I've done it once or
> twice, but I feel it's almost always better to break up whatever
> chunk of work you're doing into more manageable pieces, and let the
> window procedure process messages normally.

Yep, the minority.

There is absolutely nothing wrong, buggy, or particularly "non-normal" with
the DoEvents() function. In fact periodically halting a current process,
check the message queue, and giving up time for other applications to run is
a quite common technique for providing an App that plays well with others
and is "user-responsive".

The only gotcha is you shouldn't nest them. But nesting that kind of
mechanism is seldom an optimal strategy for any app.

-ralph



Sat, 10 Mar 2012 05:30:20 GMT  
 doevents


Quote:
> > Use a flag to stop what the loop is doing. Example air code:
> but then I need to close the program twice?

Not so.  But you will have to avoid causing the form to stay
loaded after exiting the loop.  Accessing a form property, or
a control on the form would cause it to stay loaded.

Perhaps, instead of just exiting the loop, you really need to
exit the procedure?  But if that routine was called by some
other routine, then that one too will have to avoid using form
properties, or controls.

Put a break point in the Form_Unload event and after you hit
X and break into debug mode, step through your code (hit F8)
to see where it goes and what it does.

LFS



Sat, 10 Mar 2012 05:40:23 GMT  
 doevents

Quote:

>Actually a running VB application is multi-threaded. At a minimum there is
>the App thread and a current window (Form) thread. Else how would DoEvents
>work?

DoEvents operates on one thread.  It empties the current message
queue, and (iirc) calls Sleep(0).  Neither of these activities requires
more than one thread.

--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
   Anybody remotely interesting is mad, in some way or another.
   -- The Doctor in Doctor Who:"Remembrance of the Daleks"



Sat, 10 Mar 2012 05:49:52 GMT  
 doevents


Quote:

> >Actually a running VB application is multi-threaded. At a minimum there
is
> >the App thread and a current window (Form) thread. Else how would
DoEvents
> >work?

> DoEvents operates on one thread.  It empties the current message
> queue, and (iirc) calls Sleep(0).  Neither of these activities requires
> more than one thread.

Then who is reading the message queue - while the routine that called
DoEvents is waiting for it to return?

-ralph



Sat, 10 Mar 2012 07:20:14 GMT  
 doevents
It happens synchronously as part of the call to DoEvents - that call returns
when the messages have been processed.

There is no proper multi-threading available in VB prior to .NET.

-Alex


Quote:




>> >Actually a running VB application is multi-threaded. At a minimum there
> is
>> >the App thread and a current window (Form) thread. Else how would
> DoEvents
>> >work?

>> DoEvents operates on one thread.  It empties the current message
>> queue, and (iirc) calls Sleep(0).  Neither of these activities requires
>> more than one thread.

> Then who is reading the message queue - while the routine that called
> DoEvents is waiting for it to return?

> -ralph



Sat, 10 Mar 2012 07:57:21 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. DoEvents and DBEngine.Idle questions

2. DoEvents and Form_Timer event

3. What exactly is DoEvents.....

4. DoEvents REALLY slow!

5. Unexpected error 3020 (related to DoEvents?)

6. TransferText and DoEvents

7. Use of DoEvents

8. DoEvents?

9. Sleep or DoEvents in VBA?

10. Using DoEvents while running batch files

11. DoEvents not doing any events

12. Alternative to Application.DoEvents

 

 
Powered by phpBB® Forum Software