How to Create a Zip File in VB
Zip (archive) files are containers that hold several compressed files. These several files are accessible in one large file. Zip archives are commonly used to send several documents at once in email communications. Using Visual Basic (VB), a programmer can automate the creation of a zip file using imported code and internal functions. The process is beneficial for users who create several zip files for any files created by an application.
Instructions
-
-
1
Insert the DLL file include in your project folder. (See \"Resources.\") This DLL file is used to make the zip file creation. The VB compiler does not have an internal zip file creation namespace.
-
2
Create a zip file variable and initiate the class. Initialization of the class is required to call its methods and properties. Create a variable using the following code:<br />Dim zip as CGZipFiles<br />set zip = new CGZipFiles
-
-
3
Create the zip file archive. The following code creates the zip file that is used to contain the user's documents:<br />zip.ZipFileName = \"myZipArchive.zip\"
-
4
Add documents to the zip archive. The following code adds all files in the \"myDocs\" directory to the zip file:<br />zip.AddFile \"c:\\mDocs\\*.*\"
-
5
Set the variable to nothing. This closes the zip file lock on the file. A lock is placed on the file while you add documents to the archive. Setting the variable to nothing releases the archive, so users can send or open it from the desktop. The following code closes the file:<br />set zip = nothing
-
1