Newbe question, What am I doing wrong

  • Thread starter Thread starter ken
  • Start date Start date
K

ken

Hi,
I have two questions the first is: in the example below how can I call
an event from within a statement, such as replace Stop1 with cmdStop1
which is a button on my form?
My second question again deals with the example below. Shouldn't I see
the valve of " i" counting away in the txtCount1 text box? I don't
see anything in the text box and would like to know what I'm doing
wrong. Thanks in advance for any and all help.
Regards,
Ken



Stop1 = 0
Do
For i As Integer = 1 To 10
txtCount1.Text = i
If Stop1 = 1 Then
Exit Do
End If
Next i
Loop
End Sub
 
ken said:
Hi,
I have two questions the first is: in the example below how can I
call an event from within a statement, such as replace Stop1 with
cmdStop1 which is a button on my form?

You can not call an event. Either /raise/ an event or /handle/ it.
My second question again deals with the example below. Shouldn't I
see the valve of " i" counting away in the txtCount1 text box? I
don't see anything in the text box and would like to know what I'm
doing wrong. Thanks in advance for any and all help.
Regards,
Ken



Stop1 = 0
Do
For i As Integer = 1 To 10
txtCount1.Text = i
If Stop1 = 1 Then
Exit Do
End If
Next i
Loop
End Sub


The textbox doesn't update because there is no time. There is not time
because the loop is running. If you update a control, the rectangle on the
screen is added to a list of invalid areas. The screen is (usually) not
updated immediatelly. As soon as there is time, Win sends a message to the
control (called WM_PAINT). Whenever the control receives this messages, it
paints itself. The message can not be handled before your sub returns.

To update the control immediatelly, call it's refresh method:
txtcount1.refresh. This /forces/ the immediate repaint of the control.

Be aware of a problem existing in WinXP (3rd paragraph):
http://msdn.microsoft.com/library/e...ssagequeues/aboutmessagesandmessagequeues.asp

This means, even in a tiny program, you are forced to use a second thread to
run the loop (or use application.doevents with all it's side-effects). A
work-around is to call the API function Peekmessage within the loop (in
addition to calling refresh).


Armin
 
Armin,
Thank you for answering my questions. I suspected that loop was
happening to fast to update. Once again thanks.
Ken
 
Hi Dennis and thanks, What I was trying to say is how can I check if a
Button has been Clicked from within a Loop.
Ken
 
For one thing, the button Click event won't fire until your loop finishes
unless you have a "DoEvents" statement within your loop or the loop is
executing on a NON-UI thread.

If you put a "DoEVents" statement withing your loop, you can use a boolean
variable which scoped for access both in the button click event handler and
the loop. Set the variable to False before the loop starts then set it to
true in the button click event handler and check it after the DoEvents
Statement in your loop.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top