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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to show a progress bar in a For..Next loop

Status
Not open for further replies.

titoneon

MIS
Dec 11, 2009
335
US
Hi Guys,
I have a button in a form for searching, in the Click property of the command button, i have the code below, how can i implement a progress bar while in the loop below is processing ?


For lnCtr = 1 To m.lnPaths
lcPath = Getwordnum(m.lcFolder,m.lnCtr,';')
Wait Window 'Working on '+m.lcPath+'......' At 10,125 Nowait
Thisform.SearchMe(m.lcPath, m.lcFile)
Next

Thanks in advance
 
Well, first you have to create a progessbar of some sort. It's actually pretty easy to do in VFP native controls with shape controls.

I usually write mine so they have a MaxValue property which you'd set to the upper bounds of your FOR loop, and then an Update method that does the math to figure out what percentage of the progress bar to display. Instead of your Wait Window, you'd call your progress bar's update method.

(Ironically, this was a demo I did during VFP's beta in the early 1990's. It is NOT difficult!)

What have you tried? What didn't work?
 
In your case you could simply display another info with your wait window:

Code:
Wait Window 'Working on '+m.lcPath+', ('+;
Transform(m.lnCtr)+' of '+Transform(m.lnPaths)+;
')' At 10,125 Nowait

If you only have three paths and they have very different number of files in them, your progress will not show a linear progress, you might have (1/3) and (2/3) proceed very fast and then seem to get stuck in (3/3). Then you would then have this main progress, but more informative you'd also need to show the progress within the SearchMe method.

If you want to show an overall progress, you'd need to determine the whole list of files first and maybe even their size, to better predict the progress by the bytes processed in comparison with overall bytes.

Estimation is not an easy task.

Bye, Olaf.
 
There are dozens of ready-made progress bars available on various Foxpro-related websites, including right here on Tek Tips (see, for example, faq184-5535). Confusingly, they are often called thermometers - don't ask me why.

But it's pretty easy to create your own. You start with a Shape object to represent a thick horizontal bar. Give it an initial Width property of zero. Then, each time round the loop, you increase the Width slightly until it reaches its maximum. Experiment with its cosmetics to get it to look the way you like.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top