Loop not behaving as expected

  • Thread starter Thread starter StrandElectric
  • Start date Start date
S

StrandElectric

Making good progress with my UDT app, but loops are not behaving as
expected. Here's the code of my test program. Any SIMPLE comment on what I'm
doing wrong?

(Incidentally, I wonder why my copied and pasted code finishes up double
spaced?)



Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

TestLabel.Text = "starting"

End Sub

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

For x = 1 To 500

Debug.Print(x) ' the iterations of the loop are shown correctly in the
immediate window

TestLabel.Text = x 'but the label is not updated and no number appears until
the end

Next x

End Sub

End Class
 
Dennis said:
Follow this with...

TestLabel.Refresh()

Thank you Dennis! That did it. Perfect simple answer. Funny, I had tried
that but instictively had put the Refresh *before*!
 
I had tried
that but instictively had put the Refresh *before*!

If it was still in the loop, that should have worked also. It just would
have been behind by one iteration.
 
Am 12.01.2011 20:26, schrieb StrandElectric:
Thank you Dennis! That did it. Perfect simple answer. Funny, I had tried
that but instictively had put the Refresh *before*!


Be aware that this works, but only for short loops. If Windows considers the
thread to be hung-up, refreshing stops even if you call Refresh. The solution
is putting the work in another thread, but this is an advanced technique.

This behavior is described in the following link in the 3rd paragraph:
http://msdn.microsoft.com/en-us/library/ms644927(VS.85).aspx
 
Armin Zingler said:
Am 12.01.2011 20:26, schrieb StrandElectric:


Be aware that this works, but only for short loops. If Windows considers
the
thread to be hung-up, refreshing stops even if you call Refresh. The
solution
is putting the work in another thread, but this is an advanced technique.

This behavior is described in the following link in the 3rd paragraph:
http://msdn.microsoft.com/en-us/library/ms644927(VS.85).aspx

My loop (through a random file) is under 8,500 iterations. I have printed
out that MSDN stuff but it is way too complicated for me!
 
Am 12.01.2011 23:10, schrieb StrandElectric:
My loop (through a random file) is under 8,500 iterations. I have printed
out that MSDN stuff but it is way too complicated for me!

Don't print it out. Read only one single paragraph. It says that your
window is hidden and replaced by a "ghost window". There is no output
in the ghost window. What's the complicated part?
 
Armin Zingler said:
Am 12.01.2011 23:10, schrieb StrandElectric:

Don't print it out. Read only one single paragraph. It says that your
window is hidden and replaced by a "ghost window". There is no output
in the ghost window. What's the complicated part?

Well, as you gave me the URL I thought it was all to be read!
 
Strand,

Everybody can have his own opinion in my idea.

I have read mome times currently in this newsgroup to refresh,

One of those opinions from me is that refresh is solving something with a
bandage.

There should be a reason for the problem.

Be aware as a loop is running in a method your UI freezes, it is like that.

An solution is the do events, which gives always in newsgroups and forums a
bunch of comment, because it is known not to do that.
"And then I see a bunch of argumentations from the time even before VB6 and
never one for modern CPU's and OS systems"

However, to solve a non wanted situation with an even worse instruction for
time consumption, than do events is in my idea no solution.

Be aware that while you are debugging everything goes billions time slower
(because of breaks) than in the actual situation of your program without
debugging.

imo

Cor



"StrandElectric" wrote in message
Making good progress with my UDT app, but loops are not behaving as
expected. Here's the code of my test program. Any SIMPLE comment on what I'm
doing wrong?

(Incidentally, I wonder why my copied and pasted code finishes up double
spaced?)



Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

TestLabel.Text = "starting"

End Sub

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

For x = 1 To 500

Debug.Print(x) ' the iterations of the loop are shown correctly in the
immediate window

TestLabel.Text = x 'but the label is not updated and no number appears until
the end

Next x

End Sub

End Class
 
Cor said:
Strand,

Everybody can have his own opinion in my idea.

I have read mome times currently in this newsgroup to refresh,

One of those opinions from me is that refresh is solving something with a
bandage.

There should be a reason for the problem.

Be aware as a loop is running in a method your UI freezes, it is like
that.

An solution is the do events, which gives always in newsgroups and forums
a bunch of comment, because it is known not to do that.
"And then I see a bunch of argumentations from the time even before VB6
and never one for modern CPU's and OS systems"

However, to solve a non wanted situation with an even worse instruction
for time consumption, than do events is in my idea no solution.

Be aware that while you are debugging everything goes billions time slower
(because of breaks) than in the actual situation of your program without
debugging.

imo

Cor



"StrandElectric" wrote in message
Making good progress with my UDT app, but loops are not behaving as
expected. Here's the code of my test program. Any SIMPLE comment on what
I'm
doing wrong?

(Incidentally, I wonder why my copied and pasted code finishes up double
spaced?)



Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

TestLabel.Text = "starting"

End Sub

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

For x = 1 To 500

Debug.Print(x) ' the iterations of the loop are shown correctly in the
immediate window

TestLabel.Text = x 'but the label is not updated and no number appears
until
the end

Next x

End Sub

End Class

??!!
 
Strand,

I never use the immediate window, I always use the quick watch, I also don't
use compile and continue, maybe is that the reason for that.

So don't expect an good answer from me on questions around the immediate
window.

Cor

"StrandElectric" wrote in message

Cor said:
Strand,

Everybody can have his own opinion in my idea.

I have read mome times currently in this newsgroup to refresh,

One of those opinions from me is that refresh is solving something with a
bandage.

There should be a reason for the problem.

Be aware as a loop is running in a method your UI freezes, it is like
that.

An solution is the do events, which gives always in newsgroups and forums
a bunch of comment, because it is known not to do that.
"And then I see a bunch of argumentations from the time even before VB6
and never one for modern CPU's and OS systems"

However, to solve a non wanted situation with an even worse instruction
for time consumption, than do events is in my idea no solution.

Be aware that while you are debugging everything goes billions time slower
(because of breaks) than in the actual situation of your program without
debugging.

imo

Cor



"StrandElectric" wrote in message
Making good progress with my UDT app, but loops are not behaving as
expected. Here's the code of my test program. Any SIMPLE comment on what
I'm
doing wrong?

(Incidentally, I wonder why my copied and pasted code finishes up double
spaced?)



Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

TestLabel.Text = "starting"

End Sub

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

For x = 1 To 500

Debug.Print(x) ' the iterations of the loop are shown correctly in the
immediate window

TestLabel.Text = x 'but the label is not updated and no number appears
until
the end

Next x

End Sub

End Class

??!!
 
Cor,

Mr. Strand's efforts in his age of 70 (or 71?) are highly respected
and appreciated! What I've learned from him for my life is that it's
not always the _perfect_ way that you can walk slower or faster because
an individual way is an option, too.

Just some thoughts.

:-)
 
Armin,

It was not Strand who was writing about refresh.

Who did it did it with his own opinion, like I did that with my opinion.

:-)

Cor

"Armin Zingler" wrote in message
Cor,

Mr. Strand's efforts in his age of 70 (or 71?) are highly respected
and appreciated! What I've learned from him for my life is that it's
not always the _perfect_ way that you can walk slower or faster because
an individual way is an option, too.

Just some thoughts.

:-)
 
Back
Top