Discussion:
A little help
(too old to reply)
Stl Mongo
2015-04-05 13:34:47 UTC
Permalink
I have some code that I can't seem to get to work properly. What I want
to do is loop through an array of integers and display a string during
each iteration to a label. I also want a delay between each iteration.
So, get first number, display on label, wait, get second number added to
first, display both, and so on.

Right now, what I have seems to go through each iteration, but doesn't
display each. After the loop finishes (delay works) it displays the
final string on the label.

Here is my code for that section:

For i = 0 To (numDrawn - 1)
strResults += (arrNumbers(i).ToString + " ")
Me.lblResults.Text = strResults
watch.Start()
Do Until watch.ElapsedMilliseconds > 1000
Loop
watch.Reset()
Next

Can anyone help me get this to work as wanted?

Thanks,
Mongo
Ron Weiner
2015-04-05 15:14:07 UTC
Permalink
Try

Me.lblResults.Text = strResults
DoEvents()
watch.Start()

Rdub
Stl Mongo
2015-04-05 17:46:14 UTC
Permalink
Post by Stl Mongo
Try
Me.lblResults.Text = strResults
DoEvents()
watch.Start()
Rdub
Thanks for the help but that didn't do it either.
I finally got it, I had to add lblResults.Refresh()
in the loop and now it's fine.

Mongo
mike
2015-04-07 08:06:19 UTC
Permalink
Post by Stl Mongo
Post by Stl Mongo
Try
Me.lblResults.Text = strResults
DoEvents()
watch.Start()
Rdub
Thanks for the help but that didn't do it either.
I finally got it, I had to add lblResults.Refresh()
in the loop and now it's fine.
Mongo
DoEvents() should have worked.

Your loop uses a lot of horsepower, yes?
The sleep statement should let something else run
while it waits.
Michael Cole
2015-04-07 22:11:06 UTC
Permalink
Post by Stl Mongo
Post by Stl Mongo
Try
Me.lblResults.Text = strResults
DoEvents()
watch.Start()
Rdub
Thanks for the help but that didn't do it either.
I finally got it, I had to add lblResults.Refresh()
in the loop and now it's fine.
Mongo
One thing that you should probably also do is note the version of VB
that you are using. VB.Net and VB Classic (6 and below) are completely
different beasts, and most questions herte are for VB6.

Otherwise you are just asking for confusion...
--
Michael Cole
Stl Mongo
2015-04-07 22:24:37 UTC
Permalink
Post by Michael Cole
Post by Stl Mongo
Post by Stl Mongo
Try
Me.lblResults.Text = strResults
DoEvents()
watch.Start()
Rdub
Thanks for the help but that didn't do it either.
I finally got it, I had to add lblResults.Refresh()
in the loop and now it's fine.
Mongo
One thing that you should probably also do is note the version of VB
that you are using. VB.Net and VB Classic (6 and below) are completely
different beasts, and most questions herte are for VB6.
Otherwise you are just asking for confusion...
I'm using .NET (VB 2012). The issue I was having was with the text on
the label not showing during each iteration. By adding the Refresh()
function I was able to fix that.

I actually went back after earlier today and commented out the Refresh()
and tried DoEvents() again and it worked that way also. I'm not sure why
it didn't work before, but I'm sure it was my mistake.

Thanks again for your help.

Mongo
Deanna Earley
2015-04-08 09:51:54 UTC
Permalink
Post by Stl Mongo
I'm using .NET (VB 2012). The issue I was having was with the text on
the label not showing during each iteration. By adding the Refresh()
function I was able to fix that.
I actually went back after earlier today and commented out the Refresh()
and tried DoEvents() again and it worked that way also. I'm not sure why
it didn't work before, but I'm sure it was my mistake.
Thanks again for your help.
In summary, drawing (updated text or graphics) is normally only done
when you explicitly ask for a redraw (with .Refresh) or the message pump
is run (DoEvents).

Most graphical operations just update internal state and set a flag
saying "redraw required". This stops CPU being chewed up when something
isn't actually visible.
--
Deanna Earley (***@earlsoft.co.uk, ***@doesnotcompute.co.uk)

(Replies direct to my email address will be printed, shredded then fed
to the rats. Please reply to the group.)
Loading...