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

Adding a progress bar to a .zip operation

General

Adding a progress bar to a .zip operation

by  ChrisRChamberlain  Posted    (Edited  )
If you need to add compression to a VFP app, look no further than Craig Boyd's excellent VFPcompression.fll.

Free and fast, documentation and download are available at http://www.sweetpotatosoftware.com/SPSBlog/CommentView,guid,07ed8874-8781-4e76-878b-92b3f4cfc8b3.aspx#commentstart

Under certain circumstances, it's possible to utilise the callback feature to populate a progress bar.

The purpose of this FAQ is to show how to use the callback feature to gather the necessary data - the actual implementation of the progress bar is left to the individual developer.

The .prg that follows utilises the ZipFolderQuick() function - if you substitute your own folder for "tablesbackup", you can run the code and see how it works.

The two values required for a progress bar are :-

oZipData.nFiles2Zip
oZipData.nFileCount

So to calculate the percentage of files zipped, divide oZipData.nFileCount by oZipData.nFiles2Zip and multiply by 100

As well as populating the progress bar, the other values generated in the function, together with the use of ADIR(), may be used for form label captions such as:-

Current file being zipped and filesize
Last file zipped and filesize
Total files to zip
Total files zipped
Total bytes written

At the end of the operation, you can also display time taken for the operation, filesize of the .zip file and calculate compression percentage.

See also faq1251-6888

Code:
[color blue]
CLEA
SET LIBRARY TO LOCFILE([vfpcompression.fll])

oZipData = CREATEOBJECT([Empty])
ADDPROPERTY(oZipData,[cZipObjectName],[])
ADDPROPERTY(oZipData,[nFileCount],0)
ADDPROPERTY(oZipData,[nFiles2Zip],0)
ADDPROPERTY(oZipData,[nBytesRead],0)
ADDPROPERTY(oZipData,[nTotalBytes],0)

oZipData.nFiles2Zip = ADIR(laTemp,[tablesbackup\*.*])
MESSAGEBOX([No of files to zip is ] + [tab]TRANSFORM(oZipData.nFiles2Zip))

ZipCallBack([ZipStatus()])
ZipFolderQuick(ADDBS(SYS(5) + SYS(2003)) + [tablesbackup],.F.)
ZipCallBack([])

RELEASE oZipData, laTemp
SET LIBRARY TO
[/color][color green]
*!* *!* *!* *!* *!* *!*[/color][color blue]
FUNCTION ZipStatus()[/color][color green]
*!* *!* *!* *!* *!* *!*[/color][color blue]
DO CASE
CASE nZipEvent = 0
[tab]? [Opening ] + cZipObjectName
CASE nZipEvent = 2
[tab]oZipData.nBytesRead = nZipBytes
CASE nZipEvent = 5
[tab]? [Closing ]  + cZipObjectName
CASE oZipData.cZipObjectName = cZipObjectName
[tab]? TRANSFORM(oZipData.nBytesRead) ;
[tab][tab]+ [ bytes read]
CASE oZipData.cZipObjectName # cZipObjectName
[tab]oZipData.cZipObjectName = cZipObjectName
[tab]oZipData.nFileCount = oZipData.nFileCount ;
[tab][tab]+ 1
[tab]oZipData.nTotalBytes = oZipData.nTotalBytes ;
[tab][tab]+ oZipData.nBytesRead
[tab]? [Filename is ] ;
[tab][tab]+ PROPER(LOWER(JUSTFNAME(cZipObjectName)))
[tab]? [Zipped files count is ]	;
[tab][tab]+ TRANSFORM(oZipData.nFileCount)
[tab]? [Total bytes zipped is ]	;
[tab][tab]+ TRANSFORM(oZipData.nTotalBytes)
[tab]? [Files zipped is ] ;
[tab][tab]+ TRANSFORM(INT(oZipData.nFileCount / [tab][tab]oZipData.nFiles2Zip * 100)) ;
[tab][tab]+ [%][/color][color green] && Percentage value for progress bar[/color][color blue]
ENDCASE

ENDFUNC[/color][color green]
* EOF[/color]
Any suggestions for improvements always welcome
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top