By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,258 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,258 IT Pros & Developers. It's quick & easy.

How to: Doevent()

P: n/a
I've looked in the July 2003 version of the MSDN Library and I'm not getting
much support on the Application.DoEvent method. I've written a small app to
get an idea of how it works and am having some difficulty. I simply want
the program to process the Ones() and Tens() subroutines at the same time
and when I press the "Stop" button, the program ends, but with the code
below, its only processing the Ones() subroutines and never gets to the
Tens(). Thanks to all that reply!

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Button1.Text = "Start" Then
Button1.Text = "Stop"
Application.DoEvents()
Call Ones()
Call Tens()
Application.DoEvents()
Else
Application.Exit()
End If
End Sub

Private Sub Ones()
Do
Me.txtOnes.Text = Str(Val(Me.txtOnes.Text.ToString) + 1)
Me.txtOnes.Refresh()
Loop
End Sub

Private Sub Tens()
Do
Me.txtTens.Text = Str(Val(Me.txtTens.Text.ToString) + 10)
Me.txtTens.Refresh()
Loop
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
txtOnes.Text = 0
txtTens.Text = 0
End Sub
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Cor
Hi,

I changed something, and I have removed those do loops, because they would
never end.
But to give you an idea.

Cor
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Button1.Text = "Start" Then
Button1.Text = "Stop" Ones()
Tens() Else
me.close
End If
End Sub

Private Sub Ones()
Me.txtOnes.Text = Str(Val(Me.txtOnes.Text.ToString) + 1)
Me.txtOnes.Refresh()
End Sub

Private Sub Tens()
Me.txtTens.Text = Str(Val(Me.txtTens.Text.ToString) + 10)
Me.txtTens.Refresh()
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtOnes.Text = 0
txtTens.Text = 0
End Sub

Nov 20 '05 #2

P: n/a
Cor...the loop will stop when I press the "Stop" button. As you will see, I
had and application.exit command. But back to my original question, where
do I put the "application.doevent()" commands, so that both routines run
simultaneously?

"Cor" <no*@non.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

I changed something, and I have removed those do loops, because they would
never end.
But to give you an idea.

Cor
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Button1.Text = "Start" Then
Button1.Text = "Stop"

Ones()
Tens()
Else
me.close
End If
End Sub

Private Sub Ones()
Me.txtOnes.Text = Str(Val(Me.txtOnes.Text.ToString) + 1)
Me.txtOnes.Refresh()
End Sub

Private Sub Tens()
Me.txtTens.Text = Str(Val(Me.txtTens.Text.ToString) + 10)
Me.txtTens.Refresh()
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As

System.EventArgs)
Handles MyBase.Load
txtOnes.Text = 0
txtTens.Text = 0
End Sub


Nov 20 '05 #3

P: n/a
"Jerry Haynes" <je***@blackcreektech.on.ca> wrote...
Cor...the loop will stop when I press the "Stop" button. As you will see, I had and application.exit command. But back to my original question, where
do I put the "application.doevent()" commands, so that both routines run
simultaneously?


Jerry... the loop "stops" because an event interrupted it. Otherwise it is
an endless loop and it will never get to the Tens() routine so long as it
doesn't complete the Ones() routine and you have prevented it from ever
"finishing" because of the endless loop.

At the very least move your loop into the Button1_Click (remove them from
the Ones() and Tens() routines.

Do
Call Ones()
Call Tens()
Application.DoEvents()
Loop
Nov 20 '05 #4

P: n/a
"Jerry Haynes" <je***@blackcreektech.on.ca> schrieb
Cor...the loop will stop when I press the "Stop" button. As you will
see, I had and application.exit command. But back to my original
question, where do I put the "application.doevent()" commands, so
that both routines run simultaneously?


DoEvents does not make the routines run simultaneously. DoEvents processes
the messages in the message loop (like mouse and keyboard messages) for the
current thread. To have two routines run simultaneously, you must create two
threads.

see also:

http://msdn.microsoft.com/library/en...nthreading.asp
http://msdn.microsoft.com/library/en...isualBasic.asp
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #5

P: n/a
"Armin Zingler" <az*******@freenet.de> schrieb
DoEvents does not make the routines run simultaneously. DoEvents
processes the messages in the message loop (like mouse and keyboard


Correction:
.... in the message _queue_ ...

:)
--
Armin

Nov 20 '05 #6

P: n/a
Cor
Hi Jerry,
Just as an addition to Tom and Armin

To add the example of Tom, you could do something as
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Select case Button1.text
case "Start"
Button1.Text="Tens"
Ones
case "Tens"
Button1.Text="Stop"
Tens
case "Stop"
me.close ' that is your application exit
end select
End sub

And then add that application.doevents like Tom did also in the Tens routine
but than with the do ....... loop.

Then fist the Ones do a loop till you push and then the tens do that loop

This just an addition two the two answers like I said.

Cor
Cor
Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.