Question Locked

Time Loop

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Cannot understand why first TextBox instruction in next code does not work.

Public Class Form1
Dim Value As Double
Dim Begin As Double
Dim Eind As Double
Dim Verstreken As Double
Dim Duur As Double = 5.45

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

TextBox1.Text = "Program runs"

Begin = DateAndTime.Timer

Do While Verstreken <= Duur

Eind = DateAndTime.Timer
Verstreken = Eind - Begin
Loop

TextBox1.Text = Str(Verstreken)

End Sub

End Class

Can anyone give me an explanation pls.

3 replies

by tony hopkinson

Program Runs

TextBox1.Text = "Program runs"
DoEvents
....

That will process any outstanding windows mesages which includes the request to redraw
the edit box. Your process is so busy in the loop there's no time to process the queue.

Note if you expect to do things UI wise within the loop (e.g click an cancel button) then you need to put DoEvents inside the loop, to get a response from the window(s).

This discussion is closed to new replies.