469,338 Members | 8,589 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,338 developers. It's quick & easy.

updating variable from button during running process

Hello all, This is my first time posting a question to this forum, so here is
hoping I am following protocol. I am scraping the rust off my old Basic
programming skills, and have just recently upgraded to VB.NET, and I have a
lot of catching up to do. That being said, I have come a long way in a short
while, however, I am stumped at the moment. I have read through days of
posts, but have not been able to address my specific question, so here is
hoping I can find the answer on this site.

I have a running process that generates random numbers, and displays those
results on the forms page by means of both graphics and a textbox. My control
buttons on the form would allow the user to disrupt the process, as in either
a pause, or begin again mode. I have created a control array that places the
'AutoGenerate' button, the 'Pause' button, and the 'ReStart' button in the
same event handler. I expected that the program would recognize when the user
selected a button such as 'Pause while in the 'AutoGenerate' mode that would
allow me to use an 'If ....Then' statement to detect that a different control
had been selected and then react accodingly, as in 'pause' the program or
restart the program, depending on which button was selected, but instead,
when I click on anything after having selected the 'AutoGenerate' mode, while
in debug mode, the program just crashes, leaving me a large white area at the
bottom of the screen, and the need to 'Ctrl,Alt,Dlete' to get back to the
code window.

How do I get the program to recognize that a different control had been
selected during a running process, and act upon the controls intended
purpose, such as changing the value of a variable or the like? Any help would
be appreciated. Thankyou.
Nov 21 '05 #1
7 2345
Is the process that is generating the random numbers just a loop?
While not paused
GenerateRandonNumber
Wend

Something like that?
If it is then try:
While not paused
GenerateRandonNumber
Application.DoEvents
Wend

It could be that you are running in a loop that doesn't allow the program to
process other events.

Hope this helps.
Chris.
"MgGuigg" wrote:
Hello all, This is my first time posting a question to this forum, so here is
hoping I am following protocol. I am scraping the rust off my old Basic
programming skills, and have just recently upgraded to VB.NET, and I have a
lot of catching up to do. That being said, I have come a long way in a short
while, however, I am stumped at the moment. I have read through days of
posts, but have not been able to address my specific question, so here is
hoping I can find the answer on this site.

I have a running process that generates random numbers, and displays those
results on the forms page by means of both graphics and a textbox. My control
buttons on the form would allow the user to disrupt the process, as in either
a pause, or begin again mode. I have created a control array that places the
'AutoGenerate' button, the 'Pause' button, and the 'ReStart' button in the
same event handler. I expected that the program would recognize when the user
selected a button such as 'Pause while in the 'AutoGenerate' mode that would
allow me to use an 'If ....Then' statement to detect that a different control
had been selected and then react accodingly, as in 'pause' the program or
restart the program, depending on which button was selected, but instead,
when I click on anything after having selected the 'AutoGenerate' mode, while
in debug mode, the program just crashes, leaving me a large white area at the
bottom of the screen, and the need to 'Ctrl,Alt,Dlete' to get back to the
code window.

How do I get the program to recognize that a different control had been
selected during a running process, and act upon the controls intended
purpose, such as changing the value of a variable or the like? Any help would
be appreciated. Thankyou.

Nov 21 '05 #2
Thank you for your respone, I will try to clarify...
Button1.text = "ReStart"
Button8.text = "Continuous Draw"
Button10.text = "Pause"

The selection of button8 allows the execution of a continuous random number
to be generated and displayed. There is some graphics and some comparison
being done, but all this is working ok. After I select Button8 and after a
while decide to Pause or decide to ReStart by selecting button10 or Button1,
I would hope that the Continuous Draw loop would suspend, and the button
selected would execute.

Here is a sample of what I have...
While Button8.Focus = TRUE
'< I have added the App.DoEvent here on your suggestion..>
Application.DoEvents()
.....and here I create the random number etc....
End While

If Button10.focus = TRUE then
'... this is where I would put the pause event....
End If

If Button1.focus = TRUE then
' .... I am not sure how to reStart the module ....'
End If

However, it seems that any selection of button after Button8 has been
selected, is not being read into the program....I suspect that my ... If
focus...' statements are not the type I should be using to read whether a
button has been pressed...

Any further thoughts???


"Chris Podmore" wrote:
Is the process that is generating the random numbers just a loop?
While not paused
GenerateRandonNumber
Wend

Something like that?
If it is then try:
While not paused
GenerateRandonNumber
Application.DoEvents
Wend

It could be that you are running in a loop that doesn't allow the program to
process other events.

Hope this helps.
Chris.
"MgGuigg" wrote:
Hello all, This is my first time posting a question to this forum, so here is
hoping I am following protocol. I am scraping the rust off my old Basic
programming skills, and have just recently upgraded to VB.NET, and I have a
lot of catching up to do. That being said, I have come a long way in a short
while, however, I am stumped at the moment. I have read through days of
posts, but have not been able to address my specific question, so here is
hoping I can find the answer on this site.

I have a running process that generates random numbers, and displays those
results on the forms page by means of both graphics and a textbox. My control
buttons on the form would allow the user to disrupt the process, as in either
a pause, or begin again mode. I have created a control array that places the
'AutoGenerate' button, the 'Pause' button, and the 'ReStart' button in the
same event handler. I expected that the program would recognize when the user
selected a button such as 'Pause while in the 'AutoGenerate' mode that would
allow me to use an 'If ....Then' statement to detect that a different control
had been selected and then react accodingly, as in 'pause' the program or
restart the program, depending on which button was selected, but instead,
when I click on anything after having selected the 'AutoGenerate' mode, while
in debug mode, the program just crashes, leaving me a large white area at the
bottom of the screen, and the need to 'Ctrl,Alt,Dlete' to get back to the
code window.

How do I get the program to recognize that a different control had been
selected during a running process, and act upon the controls intended
purpose, such as changing the value of a variable or the like? Any help would
be appreciated. Thankyou.

Nov 21 '05 #3
Hi Chris, My last response to your post went somewhere, but I got an error
returned, so I will try this again...

First, thank you for your respone, I am sure that I will require that line
of code in my module...

Here is what I have...
Button1.text = " ReStart"
Button8.text = "Continuous Draw"
Button10.text = "Pause"

While Button8.Focus = True
'... I added your suggestion here....
Application.DoEvents()
' ... This is where I generate the random number etc., there is some
graphics
' ... and comparison going on, but all this works ok...
End While

If Button10.focus = TRUE then
' ... this is where I would place the pause event '
End If

If Button1.focus = TRUE then
' I am not sure how to get the module to restart....
End If

Once I select the Continuous Draw button with the mouse, the program
responds by generating random numbers and doing the comparisons and the
graphics, this part works ok, however, if after a bit I try to select
Button10 to Pause, or Button1 to ReStart the program initially just crashed,
but since I have added the line of code you suggested - Application.DoEvents
it appears that the new selected button is being selected (at least it
appears so because the button will show a depressed state while clicked on)
however, the program does not exit the Continuous Draw mode and just seems to
remain in the While loop...
Any suggestions??

"Chris Podmore" wrote:
Is the process that is generating the random numbers just a loop?
While not paused
GenerateRandonNumber
Wend

Something like that?
If it is then try:
While not paused
GenerateRandonNumber
Application.DoEvents
Wend

It could be that you are running in a loop that doesn't allow the program to
process other events.

Hope this helps.
Chris.
"MgGuigg" wrote:
Hello all, This is my first time posting a question to this forum, so here is
hoping I am following protocol. I am scraping the rust off my old Basic
programming skills, and have just recently upgraded to VB.NET, and I have a
lot of catching up to do. That being said, I have come a long way in a short
while, however, I am stumped at the moment. I have read through days of
posts, but have not been able to address my specific question, so here is
hoping I can find the answer on this site.

I have a running process that generates random numbers, and displays those
results on the forms page by means of both graphics and a textbox. My control
buttons on the form would allow the user to disrupt the process, as in either
a pause, or begin again mode. I have created a control array that places the
'AutoGenerate' button, the 'Pause' button, and the 'ReStart' button in the
same event handler. I expected that the program would recognize when the user
selected a button such as 'Pause while in the 'AutoGenerate' mode that would
allow me to use an 'If ....Then' statement to detect that a different control
had been selected and then react accodingly, as in 'pause' the program or
restart the program, depending on which button was selected, but instead,
when I click on anything after having selected the 'AutoGenerate' mode, while
in debug mode, the program just crashes, leaving me a large white area at the
bottom of the screen, and the need to 'Ctrl,Alt,Dlete' to get back to the
code window.

How do I get the program to recognize that a different control had been
selected during a running process, and act upon the controls intended
purpose, such as changing the value of a variable or the like? Any help would
be appreciated. Thankyou.

Nov 21 '05 #4
Hummm ...

This is your problem. The Button8.Focus While loop never exits. Why? Well
your application is running on one thread so an event has to complete so
that another can be processed. The Application.DoEvents() allows other
events to be generated BUT they can not be processed until the current event
from your Button8 click has completed. Therefore the While loop never gets
to process the new state of the focus and the other clicks are never
processed.

Solution? We really should not have heavy code in a click event like this.
Put your generation and graphic code in a form level private Sub and call
this from Button8 asyncronously. This way the event handeler is free to
process further events. Use the Delegate object to setup your asyncronous
calls.

Well then, how do you pause and resume? Declare your state data (the random
number and the graphics storage) as private form level variables. Create a
private form level state enumeration. For example: Enum RandGenerationState
As Short {Start, Stop, Active, Pause, Resume}. Declare a private form level
variable of type RandGenerationState = RandGenerationState.Stop. The Button
event handlers job is to check the state of this variable, update it and if
nessecary make the relevent asycronous call. The asycronous method in its
loop checks its state and conducts its self accordingly.

Here is some very rough pusedo-code using your design with the button focus.
I am using Hungarian notation for clarity of the pusedo-code. You should
use the .Net PascalCase and camelCase as per the .Net guidelines.
################################################## #

Enum RandGenState As Short {Start, Stop, Active, Pause, Resume}

Dim rgsCurrentState As RandGenState = RandGenState.Stop
Dim grGraphics As (GraphicStuff)
Dim al_dblRanNums As New ArrayList

Sub ButtonArrayClick() Handles ArrayButtonsClicking

If focus is Start then
If rgsCurrentState = RandGenState.Stop then
rgsCurrentState = RandGenState.Start
async call DoRandGeneration
Else
Show "Dummy! You can't do that!"
End If

If focus is Pause then
If rgsCurrentState = RandGenState.Active then
rgsCurrentState = RandGenState.Pause
'The async DoRandGeneration will pause it
Else
Show "Idiot! Its not even running!"
End If
End If

If focus is Resume then
If rgsCurrentState = RandGenState.Pause then
rgsCurrentState = RandGenState.Resume
async call DoRandGeneration
Else
Show "Nimrod! You can't resume if its not paused"
End If
End If

If focus is Stop then
If rgsCurrentState = RandGenState.Active Or _
rgsCurrentState = RandGenState.Pause then
If rgsCurrentState = RandGenState.Active then
rgsCurrentState = RandGenState.Stop
'The async DoRandGeneration will stop it
Else
rgsCurrentState = RandGenState.Stop
'The async DoRandGeneration is not running so we manually
clear
call async ClearRandGeneration
End If
Else
Show "Loser! Next time use a dice and crayon!"
End If

Show "Abort, Retry, Ingore"

End Sub

Sub DoRandGeneration()

Dim lngIndex as Long = 0

'Setup for resume
If rgsCurrentState = RandGenState.Resume then
lngIndex = al_dblRanNums.Count
rgsCurrentState = RandGenState.Start
End If

'Check starting
If rgsCurrentState = RandGenState.Start then
rgsCurrentState = RandGenState.Active
End

Do While rgsCurrentState = RandGenState.Active
<Do your stuff>
Loop

Select Case rgsCurrentState
Case RandGenState.Pause
<pause clean up>
Case RandGenState.Stop
call ClearRandGeneration
End Select

End Sub

Sub Clear RandGeneration
grGraphics.FinalPaint
al_dblRanNums.Clear
End Sub

###################################

--Robby

MCSD VB6 (currently updating)


"MgGuigg" <Mg*****@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
Thank you for your respone, I will try to clarify...
Button1.text = "ReStart"
Button8.text = "Continuous Draw"
Button10.text = "Pause"

The selection of button8 allows the execution of a continuous random
number
to be generated and displayed. There is some graphics and some comparison
being done, but all this is working ok. After I select Button8 and after a
while decide to Pause or decide to ReStart by selecting button10 or
Button1,
I would hope that the Continuous Draw loop would suspend, and the button
selected would execute.

Here is a sample of what I have...
While Button8.Focus = TRUE
'< I have added the App.DoEvent here on your suggestion..>
Application.DoEvents()
.....and here I create the random number etc....
End While

If Button10.focus = TRUE then
'... this is where I would put the pause event....
End If

If Button1.focus = TRUE then
' .... I am not sure how to reStart the module ....'
End If

However, it seems that any selection of button after Button8 has been
selected, is not being read into the program....I suspect that my ... If
focus...' statements are not the type I should be using to read whether a
button has been pressed...

Any further thoughts???

..
Nov 21 '05 #5

One thing I did not clarify completely. The Application.DoEvents() does not
execute your code in this case because all your button events have the same
handler. The other events can be processed because their handlers are not
active. Your global click event is active during the DoEvents so the new
click events are queued to be processed once the current click event
completes. However, the current click event completing is conditional on
the current handler being processed. Therefore your While loop never exits.
You would not have this problem if you used a different handler for each
button click event. Then you could do your generation syncronously. You
would still need to have a DoRandGeneration and ClearRandGeneration Sub
since some of the other event handlers need to call it. Finally you would
definately still need the RandGenState enumeration for state management.
For this design simply move each If stament from the global click handler to
each of there own handelers and place a do events inside the
DoRandGeneration Do While loop at the end.

--Robby
#### First post below ####

"Hummm ...

This is your problem. The Button8.Focus While loop never exits. Why? Well
your application is running on one thread so an event has to complete so
that another can be processed. The Application.DoEvents() allows other
events to be generated BUT they can not be processed until the current event
from your Button8 click has completed. Therefore the While loop never gets
to process the new state of the focus and the other clicks are never
processed.

Solution? We really should not have heavy code in a click event like this.
Put your generation and graphic code in a form level private Sub and call
this from Button8 asyncronously. This way the event handeler is free to
process further events. Use the Delegate object to setup your asyncronous
calls.

Well then, how do you pause and resume? Declare your state data (the random
number and the graphics storage) as private form level variables. Create a
private form level state enumeration. For example: Enum RandGenerationState
As Short {Start, Stop, Active, Pause, Resume}. Declare a private form level
variable of type RandGenerationState = RandGenerationState.Stop. The Button
event handlers job is to check the state of this variable, update it and if
nessecary make the relevent asycronous call. The asycronous method in its
loop checks its state and conducts its self accordingly.

Here is some very rough pusedo-code using your design with the button focus.
I am using Hungarian notation for clarity of the pusedo-code. You should
use the .Net PascalCase and camelCase as per the .Net guidelines.
################################################## #

Enum RandGenState As Short {Start, Stop, Active, Pause, Resume}

Dim rgsCurrentState As RandGenState = RandGenState.Stop
Dim grGraphics As (GraphicStuff)
Dim al_dblRanNums As New ArrayList

Sub ButtonArrayClick() Handles ArrayButtonsClicking

If focus is Start then
If rgsCurrentState = RandGenState.Stop then
rgsCurrentState = RandGenState.Start
async call DoRandGeneration
Else
Show "Dummy! You can't do that!"
End If

If focus is Pause then
If rgsCurrentState = RandGenState.Active then
rgsCurrentState = RandGenState.Pause
'The async DoRandGeneration will pause it
Else
Show "Idiot! Its not even running!"
End If
End If

If focus is Resume then
If rgsCurrentState = RandGenState.Pause then
rgsCurrentState = RandGenState.Resume
async call DoRandGeneration
Else
Show "Nimrod! You can't resume if its not paused"
End If
End If

If focus is Stop then
If rgsCurrentState = RandGenState.Active Or _
rgsCurrentState = RandGenState.Pause then
If rgsCurrentState = RandGenState.Active then
rgsCurrentState = RandGenState.Stop
'The async DoRandGeneration will stop it
Else
rgsCurrentState = RandGenState.Stop
'The async DoRandGeneration is not running, manually clear
call async ClearRandGeneration
End If
Else
Show "Loser! Next time use a dice and crayon!"
End If

Show "Abort, Retry, Ingore"

End Sub

Sub DoRandGeneration()

Dim lngIndex as Long = 0

'Setup for resume
If rgsCurrentState = RandGenState.Resume then
lngIndex = al_dblRanNums.Count
rgsCurrentState = RandGenState.Start
End If

'Check starting
If rgsCurrentState = RandGenState.Start then
rgsCurrentState = RandGenState.Active
End

Do While rgsCurrentState = RandGenState.Active
<Do your stuff>
Loop

Select Case rgsCurrentState
Case RandGenState.Pause
<pause clean up>
Case RandGenState.Stop
call ClearRandGeneration
End Select

End Sub

Sub ClearRandGeneration
grGraphics.FinalPaint
al_dblRanNums.Clear
End Sub

###################################

--Robby

MCSD VB6 (currently updating)


"MgGuigg" <Mg*****@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
Thank you for your respone, I will try to clarify...
Button1.text = "ReStart"
Button8.text = "Continuous Draw"
Button10.text = "Pause"

The selection of button8 allows the execution of a continuous random
number
to be generated and displayed. There is some graphics and some comparison
being done, but all this is working ok. After I select Button8 and after a
while decide to Pause or decide to ReStart by selecting button10 or
Button1,
I would hope that the Continuous Draw loop would suspend, and the button
selected would execute.

Here is a sample of what I have...
While Button8.Focus = TRUE
'< I have added the App.DoEvent here on your suggestion..>
Application.DoEvents()
.....and here I create the random number etc....
End While

If Button10.focus = TRUE then
'... this is where I would put the pause event....
End If

If Button1.focus = TRUE then
' .... I am not sure how to reStart the module ....'
End If

However, it seems that any selection of button after Button8 has been
selected, is not being read into the program....I suspect that my ... If
focus...' statements are not the type I should be using to read whether a
button has been pressed...

Any further thoughts???

..

Nov 21 '05 #6
I wouldn't use the Focus of a button to test if it's been pressed. It looks
like you are in a loop that never exits. Have a look at the reply from Robby.
If you are still stuck post and I'll try and help some more.

Chris.

"MgGuigg" wrote:
Hi Chris, My last response to your post went somewhere, but I got an error
returned, so I will try this again...

First, thank you for your respone, I am sure that I will require that line
of code in my module...

Here is what I have...
Button1.text = " ReStart"
Button8.text = "Continuous Draw"
Button10.text = "Pause"

While Button8.Focus = True
'... I added your suggestion here....
Application.DoEvents()
' ... This is where I generate the random number etc., there is some
graphics
' ... and comparison going on, but all this works ok...
End While

If Button10.focus = TRUE then
' ... this is where I would place the pause event '
End If

If Button1.focus = TRUE then
' I am not sure how to get the module to restart....
End If

Once I select the Continuous Draw button with the mouse, the program
responds by generating random numbers and doing the comparisons and the
graphics, this part works ok, however, if after a bit I try to select
Button10 to Pause, or Button1 to ReStart the program initially just crashed,
but since I have added the line of code you suggested - Application.DoEvents
it appears that the new selected button is being selected (at least it
appears so because the button will show a depressed state while clicked on)
however, the program does not exit the Continuous Draw mode and just seems to
remain in the While loop...
Any suggestions??

"Chris Podmore" wrote:
Is the process that is generating the random numbers just a loop?
While not paused
GenerateRandonNumber
Wend

Something like that?
If it is then try:
While not paused
GenerateRandonNumber
Application.DoEvents
Wend

It could be that you are running in a loop that doesn't allow the program to
process other events.

Hope this helps.
Chris.
"MgGuigg" wrote:
Hello all, This is my first time posting a question to this forum, so here is
hoping I am following protocol. I am scraping the rust off my old Basic
programming skills, and have just recently upgraded to VB.NET, and I have a
lot of catching up to do. That being said, I have come a long way in a short
while, however, I am stumped at the moment. I have read through days of
posts, but have not been able to address my specific question, so here is
hoping I can find the answer on this site.

I have a running process that generates random numbers, and displays those
results on the forms page by means of both graphics and a textbox. My control
buttons on the form would allow the user to disrupt the process, as in either
a pause, or begin again mode. I have created a control array that places the
'AutoGenerate' button, the 'Pause' button, and the 'ReStart' button in the
same event handler. I expected that the program would recognize when the user
selected a button such as 'Pause while in the 'AutoGenerate' mode that would
allow me to use an 'If ....Then' statement to detect that a different control
had been selected and then react accodingly, as in 'pause' the program or
restart the program, depending on which button was selected, but instead,
when I click on anything after having selected the 'AutoGenerate' mode, while
in debug mode, the program just crashes, leaving me a large white area at the
bottom of the screen, and the need to 'Ctrl,Alt,Dlete' to get back to the
code window.

How do I get the program to recognize that a different control had been
selected during a running process, and act upon the controls intended
purpose, such as changing the value of a variable or the like? Any help would
be appreciated. Thankyou.

Nov 21 '05 #7
Hi again,
First let me state that this reply is intended for both Rob and Chris, but
in the interest of no duplication, I am responding to the last entry on this
thread. I wish once again to thank both Rob and Chris for their time and
expertise. I mean, where would these boards be without these types of people.

I have read with great interest Rob's reply, and I will be looking alot
closer at his suggested method. I will be dissecting his response, and taking
it a step at a time, so please do not expect that I will have the re-written
code tested anytime soon.I have taken Chris' invitation to re-post as I
progress, and I can assure you that it will be both educational and fun.
Thanks Chris. I am directing every available moment to learning,
understanding, and working with VB.NET. (to the chagrin of my wife and
family...) I expect to take delivery today of a recently purchased 'Visual
Basic.Net BlackBook". I do not expect the book to all of a sudden make me an
efficient programmer, but I do expect that it will go a long way toward my
learning the required syntax etc. I would also mention that I have a deep
background in automation and have been programming PLC's and the like for
many years. I have dabbled in Python, worked a little with 'C Plus, Linux and
several other similar projects, however, I have decided to go with VB.Net,
and give it my all.

In the interest of learning VB.Net, I am using one of my old learning tools,
a favorite program that I write with any new language I undertake to learn.
This particular program is a colorful and robust version of a lotto draw type
program. I use this because it permits me to incorporate many of the
languages' features.

I have been experimenting with several approaches to my delima, the last
being a For..Next loop with the variable being set by the value expressed in
the click of the button...(easier to show than to explain...)

For z = butt To 150
Application.DoEvents()
butn = CType(sender, Button)

' ... the text box6 is so I can see what is taking place for debugging....

TextBox6.Visible = True
TextBox6.Text = " Z = " & z & " butt " & butt

butn = CType(sender, Button)

If butn.Text Is "END" Then
butt = 150
TextBox6.Text = " END BUTTON" & " Z = " & z & " butt " & butt

ElseIf butn.Text Is "Continuous Draw" Then
butt = 0
TextBox6.Text = " Continuous Draw Button" & " Z = " & z & "
butt " & butt
ElseIf butn.Text Is "PAUSE" Then
butt = 125
TextBox6.Text = " Pause Button" & " Z = " & z & " butt " &
butt
End If

z = butt
TextBox6.Text = " Z = " & z & " & " butt " & butt

' ... the following code would be the randon gen and the graphics ....
Next Z
' ... etc, etc,etc....
_____________________________

The above with the help of the textbox shows me 2 things, 1 - the button is
being recognized, as the value of Z will show the value designated by the
selected button, and 2 - I am still caught in a loop situation as the value
of Z returns to either a begin count value from 'zero' or flashes back to
continue counting from whatever value it was at prior to me clicking a
button. The idea was that Z would take on the new value, and as with the END
value, it would be set to 150, and the For..Next loop would end. However, as
I mentioned, the textbox shows that the value changes to the button value,
then quickly changes back as previously stated.

I expect that I will need to employ the concept that Rob has pointed out.
This should take me out of this loop situation and allow for the updates as
required.

I will get back to code crunching, and will respond to this thread again as
soon as I have made further progress. That could be anywhere from a few hours
(not likely) to a few days. Thanks again fellas, and here is to
programming...Cheers.

"Chris Podmore" wrote:
I wouldn't use the Focus of a button to test if it's been pressed. It looks
like you are in a loop that never exits. Have a look at the reply from Robby.
If you are still stuck post and I'll try and help some more.

Chris.

"MgGuigg" wrote:
Hi Chris, My last response to your post went somewhere, but I got an error
returned, so I will try this again...

First, thank you for your respone, I am sure that I will require that line
of code in my module...

Here is what I have...
Button1.text = " ReStart"
Button8.text = "Continuous Draw"
Button10.text = "Pause"

While Button8.Focus = True
'... I added your suggestion here....
Application.DoEvents()
' ... This is where I generate the random number etc., there is some
graphics
' ... and comparison going on, but all this works ok...
End While

If Button10.focus = TRUE then
' ... this is where I would place the pause event '
End If

If Button1.focus = TRUE then
' I am not sure how to get the module to restart....
End If

Once I select the Continuous Draw button with the mouse, the program
responds by generating random numbers and doing the comparisons and the
graphics, this part works ok, however, if after a bit I try to select
Button10 to Pause, or Button1 to ReStart the program initially just crashed,
but since I have added the line of code you suggested - Application.DoEvents
it appears that the new selected button is being selected (at least it
appears so because the button will show a depressed state while clicked on)
however, the program does not exit the Continuous Draw mode and just seems to
remain in the While loop...
Any suggestions??

"Chris Podmore" wrote:
Is the process that is generating the random numbers just a loop?
While not paused
GenerateRandonNumber
Wend

Something like that?
If it is then try:
While not paused
GenerateRandonNumber
Application.DoEvents
Wend

It could be that you are running in a loop that doesn't allow the program to
process other events.

Hope this helps.
Chris.
"MgGuigg" wrote:

> Hello all, This is my first time posting a question to this forum, so here is
> hoping I am following protocol. I am scraping the rust off my old Basic
> programming skills, and have just recently upgraded to VB.NET, and I have a
> lot of catching up to do. That being said, I have come a long way in a short
> while, however, I am stumped at the moment. I have read through days of
> posts, but have not been able to address my specific question, so here is
> hoping I can find the answer on this site.
>
> I have a running process that generates random numbers, and displays those
> results on the forms page by means of both graphics and a textbox. My control
> buttons on the form would allow the user to disrupt the process, as in either
> a pause, or begin again mode. I have created a control array that places the
> 'AutoGenerate' button, the 'Pause' button, and the 'ReStart' button in the
> same event handler. I expected that the program would recognize when the user
> selected a button such as 'Pause while in the 'AutoGenerate' mode that would
> allow me to use an 'If ....Then' statement to detect that a different control
> had been selected and then react accodingly, as in 'pause' the program or
> restart the program, depending on which button was selected, but instead,
> when I click on anything after having selected the 'AutoGenerate' mode, while
> in debug mode, the program just crashes, leaving me a large white area at the
> bottom of the screen, and the need to 'Ctrl,Alt,Dlete' to get back to the
> code window.
>
> How do I get the program to recognize that a different control had been
> selected during a running process, and act upon the controls intended
> purpose, such as changing the value of a variable or the like? Any help would
> be appreciated. Thankyou.

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

41 posts views Thread by Miguel Dias Moura | last post: by
2 posts views Thread by wsMarkM | last post: by
9 posts views Thread by Shapper | last post: by
2 posts views Thread by =?Utf-8?B?TUNN?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.