Home All Groups Group Topic Archive Search About

Newbe question, What am I doing wrong

Author
21 Jan 2006 3:04 AM
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

Author
21 Jan 2006 3:17 AM
Armin Zingler
"ken" <somewere@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.

Show quoteHide quote
> 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-us/winui/winui/windowsuserinterface/windowing/messagesandmessagequeues/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
Author
21 Jan 2006 3:37 AM
ken
Armin,
Thank you for answering my questions. I suspected that loop was
happening to fast to update. Once again thanks.
Ken
Author
21 Jan 2006 2:18 PM
Dennis
Button1.PerformClick
--
Dennis in Houston


Show quoteHide quote
"ken" wrote:

>  Armin,
> Thank you for answering my questions. I suspected that loop was
> happening to fast to update. Once again thanks.
> Ken
>
Author
22 Jan 2006 12:34 AM
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
Author
22 Jan 2006 6:48 PM
Dennis
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.
--
Dennis in Houston


Show quoteHide quote
"ken" wrote:

> 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
>