INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

General

Adding a progress bar to a .zip operation by ChrisRChamberlain
Posted: 10 Nov 08 (Edited 16 Nov 10)

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: How can I cancel out of a zip operation?

CODE


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 ] +     TRANSFORM(oZipData.nFiles2Zip))

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

RELEASE oZipData, laTemp
SET LIBRARY TO

*!* *!* *!* *!* *!* *!*

FUNCTION ZipStatus()

*!* *!* *!* *!* *!* *!*

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

ENDFUNC

* EOF
Any suggestions for improvements always welcome  

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close