"ken" <so******@out.there> schrieb
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/en...sagequeues.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