Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Progress Label with Progress Bar 1

Status
Not open for further replies.

prgmrgirl

Programmer
Feb 12, 2004
119
US
Hi all,

I have a simple progress bar and label. For each step the progress bar takes, I want to display a different message to the user in the label. It's simply not working though it seems like it should be so simple...

Here's the code:

'sets the progress bars min, max, step, & initial value
pbar.Maximum = 10000
pbar.Minimum = 0
pbar.Step = 10
pbar.Value = 0

While pbar.Value < pbar.Maximum
pbar.PerformStep()
label2.Text = choiceWords(tval)'my function
tval += 1
End While
label2.Text = "Done!"

When I debug, I see that the label's text value is changed appropriately, but it does not show on the form at all. Only the "Done" message shows at the end. Visible property is set to True. I'm not sure what's going on here.

Thanks for your help!
prgmrgirl
 
You must add "DoEvents()" after While pbar.Value < pbar.Maximum


You can also use not the label but the forms caption,So:

While pbar.Value < pbar.Maximum
pbar.PerformStep()
Me.Text = choiceWords(tval)'my function
tval += 1
End While

In this case you don't need DoEvents



-bclt
 

I thought the ME keyword was a reference to the form. So I think the proper syntax would be Me.controlname.property...

Regardless, I made the changes you suggested but it still doesn't work. The label will not change until after the while loop has finished. [sadeyes]

Does anyone else know what's happening?

 
What's happening? Sure, the process you are running is taking control of the primary thread so the graphics update of the form (which also runs on the primary thread) doesn't get a chance to run.

Easy fix:
Code:
While pbar.Value < pbar.Maximum
  pbar.PerformStep()
  label2.Text = choiceWords(tval)'my function
  tval += 1
  label2.refresh
  doevents()
End While

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Rick,

Thanks SO much. It worked.[bigcheeks]
Though I do have a question about DoEvents(). I got an error on that...am I supposed to include something for it to work?

Thanks again,
prgmrgirl
 
You need DoEvents somewhere between While and End While, however because no time consuming process is taking place, the label will change so quickly that although debug will show the changes the screen won't appear to. The main reason for a progress bar is to give the user something to look at and a guide to the remaining time during a slow process. To test this put a slow loop inside the While eg

for a = 1 to 10000
for b = 1 to 10000
for c = 1 to 10000
next c
next b
next a

and see if this makes a difference.

Don't forget to include the DoEvents, and by the way, your label assignment is fine.

Hope this helps
 
Just to warn you, adding DoEvents is going to slow the process waaaaaaaaaaaay down. So if speed is your goal, don't display the update. If you want speed and a display, only update the display in intervals/ IE:

Code:
if pbar.Value\100 = pbar.value/100 then doevents()
Only updates the screen every 100 items.

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Hey everyone,

Thanks for all the info. Here's the weird thing: it works fine without the DoEvents(). [ponder] When I tried to include DoEvents(), it wasn't recognized as a valid function. That's why I was wondering if there was something I needed to include for DoEvents() to work (Inherit Something). Since the code seems to work fine without it, I won't put it in, but for future reference, I'd like to know about the DoEvents() function.

Thanks again!
prgmrgirl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top