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

Creating A Simple Progress Bar 1

Status
Not open for further replies.

Wendz

Programmer
Aug 9, 2000
47
PH
Thank you very much for the peopole who helped me on the date and string searching including menu problems. Now, I have a another kind of problem, I is been my long desire to create a progress bar. Right now, I am using wait window to display the status like opening. I want to be more realistic in doing it, that is a progress bar. I have browsed on the archived files but it is a class and I can't see the coding on it to maximize my need. Even just a progress bar to count the number of records in a field or any funnction that has a progress bar will. More power to you all!..
 
Hi Wendz,
Check the Visual FoxPro Foundation Class Sample regarding
'Uses Progress Thermometer'. It's actually pretty easy to use. There might be some gurus out there which might have created their own class.

Hope this helps.

Yue Jeen
 
There is a progress bar in the FAQ's Tips n Tricks G, "I want to search for files with VFP ?"
 
I cleaned it up and submitted another FAQ, here is the cleanup version with just the ProgressBar portion. anyhow good luck.

*EXAMPLE
oPB = CREATEOBJECT("PROGRESSBAR","Caption Title")
oPB.counter = 0
oPB.show
FOR x = 1 to 100 STEP +.01
IF TYPE('oPB..ButtonCancel')<>U THEN &&Cancel pushed?
oPB.counter = x
ELSE
x=101
ENDIF
NEXT x

DEFINE CLASS &quot;Progressbar&quot; AS &quot;FORM&quot;
COUNTER = 0.01
Result = &quot;&quot;
BarCaption = &quot;&quot;
ButtonCancel =.F.
WildCard = .F.
ALWAYSONTOP = .T.
AUTOCENTER = .T.
SHOWWINDOW = 2 && top level form
WINDOWTYPE = 1 && Modal
DRAWMODE = 9
TITLEBAR = 1
CONTROLBOX = .F.
HEIGHT = 83
WIDTH = 264+24

ADD OBJECT &quot;oTxt&quot; AS &quot;TEXTBOX&quot; WITH ;
HEIGHT = 25, LEFT =12, WIDTH = 264, ALIGNMENT = 2, ;
TOP = 6, BACKCOLOR = RGB(255,255,255), ;
DISABLEDBACKCOLOR = RGB(255,255,255), ;
DISABLEDFORECOLOR = RGB(0,0,0), ;
ENABLED = .F., FONTBOLD = .T.

ADD OBJECT &quot;oCmd1&quot; AS &quot;COMMANDBUTTON&quot; WITH ;
CAPTION = &quot;\<Cancel&quot;, HEIGHT = 25, LEFT = 96, ;
WIDTH = 97, TOP = 48
PROCEDURE oCmd1.CLICK
nQuit = MESSAGEBOX('Are you sure you want to cancel?',4+32,thisform.caption)
If nQuit = 6 THEN
thisform.ButtonCancel =.T. &&abort search
thisform.release
ENDIF
ENDPROC

ADD OBJECT &quot;oShp&quot; AS &quot;SHAPE&quot; WITH ;
BORDERSTYLE = 0, DRAWMODE = 14, FILLSTYLE = 0

PROCEDURE INIT
PARAMETER cCaption
thisform.oshp.left=thisform.oTxt.left+1
thisform.oshp.top=thisform.oTxt.top +1
thisform.oshp.height=thisform.oTxt.height-2
thisform.oshp.visible = .T.
thisform.borderstyle = 2
thisform.caption = cCaption
ENDPROC

PROCEDURE Counter_assign
LPARAMETERS vNewVal
IF vNewVal <> thisform.counter THEN
IF vNewVal > 100 THEN
vNewVal = 100
ENDIF
thisform.counter = vNewVal
x = thisform.counter
thisform.oShp.width = x*thisform.oTxt.width/100
thisform.oTxt.value = thisform.BarCaption+ALLTRIM(STR(x))+&quot;% Complete&quot;
thisform.refresh
*Check if cancel button has been pushed Alt+C or clicked
IF MDOWN() OR CHRSAW() THEN
DOEVENTS
ENDIF
ENDIF
ENDPROC

ENDDEFINE
*EOF
 
Wendz

BlindPete's class is the all singing, all dancing classic style progress bar.

But if you ever need to include a progress bar in a form, the following are the NON DEFAULT properties for the only two additional controls required.

You will need to determine the position and size of txtProgressBar and make both controls .Visible = .T. during processing, and .Visible = .F. on EXITing the loop.

WITH THISFORM.txtProgressBar
.Alignment = 2
.DisabledBackColor = RGB(255,25,255)
.DisabledForeColor = RGB(0,0,0)
.Enabled = .F.
.TabStop = .F.
.Visible = .F.
ENDWITH

WITH THISFORM.shpProgressBar
.BackStyle = 0
.BorderStyle = 0
.DrawMode = 14
.FillColor = RGB(0,0,128)
.FillStyle = 0
.Height = && 2 less than txtProgressBar
.Top = && 2 lower than txtProgressBar
.Visible = .F.
.Width = 1
ENDWITH

The following code might be typical of table processing and needs including in whatever loop etc.

WITH THISFORM
[tab].txtProgressBar.Value = ;
[tab][tab]ALLTRIM(STR((lnCount / RECCOUNT(
)*100))) + [%]
[tab].shpProgressBar.Width = ;
[tab][tab]lnCount * THISFORM.txtProgressBar.Width / RECCOUNT(
)
ENDWITH

Chris [sig][/sig]
 
My code above has a couple of gotcha's in the example. The FAQ was approved and it has a correctly coded example.

Good Luck Wednz!
[sig]<p> Pete<br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>What your mother told you is true! You will go blind! (from moonshine anyway)[/sig]
 
Thank you guys for the great help I appreciate it very much. My program is almost complete.

[sig][/sig]
 
My program is almost complete.

If only I had a dollar for every time I uttered that... [sig]<p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br> [/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top