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

Progress Bar on a VFP 8.0 Form 1

Status
Not open for further replies.

Persmd

Programmer
May 21, 2003
38
0
0
US
I'm using VFP 8.0, and attempting to use the _therm library for the first time. I have added the library to my project, and wish to hide the _progressbar on certain forms.

My application uses Fcreate(), Fopen(), etc. to read and write to low-level files. My goal is to make the _progressbar visible while I parse and append data into FoxPro, and also while I output transaction files for QuickBooks.

I've written a lot of "Spaghetti Code" (quick but wholesome), and am somewhat familiar with forms, but am just venturing into the world of class libraries.

If anyone can help me with the code that goes into the events to make this work, it would be greatly appreciated.

Thank you.
Michael
 
Michael,
In 8.0, fire up the Task Pane Manager (from the Tools Menu or the Toolbar), then choose the Soluiton Samples (you may have to widen the pane or click on the >> to see it).

Next, open the Foundation Class samples, and go down to the "Use progress thermometer" example. If you click on the link, it'll run the code, and if you click on the 'documents with the magnifying glass", you get the same form and it's code to look at.

Note: These should work too!
Code:
MODIFY FORM (_samples+"solution\ffc\therm")
DO FORM (_samples+"solution\ffc\therm")
Post back if you don't understand this code.

Rick
 
Thanks Rick. I have looked at the sample, and examiled the code. It seems pretty simple when you want it to display the progress while it counts 5 seconds, or whatever you put in the test box. I'm just not sure how to use it when I run my program.

I want the user to click a button which executes the following code:

Procedure loadaudit
Local fn_audit, lnfile_sz, lcString, lcFile

If not used('auditrecords')
Use auditrecords
Endif

* Locate audit files
RELEASE gaAuditfils
gnauditfils = ADIR(gaAuditfils, 'f:\CustBill\Auditfils\*._IE')

IF gnAuditfils>0
* open the text file

FOR numfils=1 TO gnAuditfils
thisfile='f:\CustBill\Auditfils\'+gaAuditfils[numfils,1]
fn_audit = FOPEN(thisfile)
If fn_audit<0
msg('Could not open the audit file')
Return .F.
ENDIF
tfile1='f:\CustBill\Auditfils\'+gaAuditfils[numfils,1]
tfile2='F:\CustBill\Archive\'+gaAuditfils[numfils,1]

* make sure there is something in the file
lnfile_sz = FSEEK(fn_audit,0,2)
If lnfile_sz=0
fn_audit = FCLOSE(fn_audit)
msg('The audit file is empty')
Return .F.
Else
= FSEEK(fn_audit,0,0)
Endif
* process the data
* Do thermo WITH 'setup', 'Processing Audit Trail File'
Do WHILE !FEOF(fn_audit)
lcString = FREAD(fn_audit,254)
m.filenme=thisfile

* parse the record
m.account = substr(lcString, 1, 8)
m.userid = substr(lcString, 9, 8)
m.rectyp = substr(lcString, 17, 1)
m.partner = substr(lcString, 18, 20)
m.groupid = substr(lcString, 38, 18)
m.statflg = substr(lcString, 56, 1)
m.status = substr(lcString, 57, 15)
m.purgflg = substr(lcString, 72, 3)
m.purged = substr(lcString, 75, 15)
m.alias = substr(lcString, 90, 20)
m.priority = substr(lcString, 110, 1)
m.nmsgcls = substr(lcString, 111, 1)
m.msgcls = substr(lcString, 112, 8)
m.msgname = substr(lcString, 120, 8)
m.msgseqi = substr(lcString, 128, 5)
m.systyp = substr(lcString, 133, 8)
m.syslvl = substr(lcString, 141, 4)
m.msgcntr = substr(lcString, 145, 8)
m.msgsize = val(substr(lcString, 153, 8))
m.rcvarch = substr(lcString, 161, 8)
m.snddate = dttime(substr(lcString, 169, 6), substr(lcString, 175, 6))
m.rcvdate = dttime(substr(lcString, 181, 6), substr(lcString, 187,6))
m.seqout = substr(lcString, 193, 6)

* check if the record already exists
If seek(m.groupid, 'auditrecords', 'groupid')
* it does exist - update it
Select auditrecords
Gather memvar
Else
* it does not exist - create it
Insert into auditrecords from memvar
Endif
* Do thermo WITH 'update', lnfile_sz, FSEEK(fn_audit,0,1)
ENDDO
fn_audit = FCLOSE(fn_audit)
RENAME (tfile1) to (tfile2)
ENDFOR
ENDIF

Return .T.

********************************

The code in red is where I'm currently calling an external progress bar, but I'd much rather use the class lib that comes with FoxPro.

Michael
 
Michael,
If I understand your code, something like this should work:
Code:
[red]*Do thermo WITH 'setup', 'Processing Audit Trail File'[/red]
loTherm = NewObject("_thermometer","_therm","",'Processing Audit Trail File')
loTherm.Show()
...

[red]*                Do thermo WITH 'update', lnfile_sz, FSEEK(fn_audit,0,1)[/red]
                 lnPercent = FSEEK(fn_audit,0,1)/lnfile_sz*100
                 loTherm.Update(lnPercent, "% Complete: "+TRANS(lnPercent))
...

[red]* At the end of the Task, add the next line to close the window.[/red]
loTherm.Complete()
[red]* and then some cleanup[/red]
loTherm = .Null.
Release loTherm
Rick


 
Rick,

Thank you very much. Your code helped me very much. I was able to embed the _progressbar into an existing form, hide it and the text that's displayed above it. Then display them both when needed.

I'm doing a Top-Level form, so it's nice to have the progress bar appear (when needed) as part of the form and not as an individual form.

Basically, I dragged the _progressbar from the _therm library onto my form. Sized and positioned it. Added my code above to the click event of a command button, then before my added this code:

This.Parent._progressbar1.Visible= .T.
This.Parent.ProgBarLbl.Visible= .T.
This.Parent.ProgBarLbl.Caption="Processing Audit Trail File"
Do WHILE !FEOF(fn_audit)
code.....
lnPercent = FSEEK(fn_audit,0,1)/lnfile_sz*100
This.Parent._progressbar1.update(lnPercent)
ENDDO
This.Parent._progressbar1.Complete()

* and then some cleanup
This.Parent._progressbar1.Visible= .F.
This.Parent.ProgBarLbl.Visible= .F.

Thanks again.
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top