Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
String
Tar
Unicode
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor


VB Strings
VB Byte Array

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

Create WinZip Compatible Password-Protected Zip

Download Chilkat Zip ActiveX

Visual Basic sample code to create a WinZip compatible password-protected Zip.

Dim ZipFile As ChilkatZip2

Private Sub Command1_Click()
    
    ' Get the zip file name
    CommonDialog1.ShowOpen
    CommonDialog1.CancelError = True
    SourceFile.Text = CommonDialog1.FileName
     
End Sub

Private Sub Command2_Click()
    
    ' Create a ChilkatZip object
    Set ZipFile = New ChilkatZip2
    ZipFile.UnlockComponent UnlockCode.Text
    ZipFile.NewZip OutputZip.Text
    
    ' To create a WinZip-compatible password-protected Zip, simply
    ' set the PasswordProtect property to 1, and set a password.
    ' To unzip, WinZip will prompt for this password.
    ZipFile.PasswordProtect = 1
    ZipFile.SetPassword "secret"
    
    ' Add the disk file to the Zip object
    ZipFile.AppendFiles SourceFile.Text, 0
    
    ' See if anything was added.
    If (ZipFile.NumEntries = 0) Then
        ZipStatus.Caption = "Error, no files added to the Zip archive."
        Set ZipFile = Nothing
        Exit Sub
    End If
    
    ' Compress and write to disk.
    success = ZipFile.WriteZip()
    If (success = 0) Then
        MsgBox ZipFile.LastErrorText
        Exit Sub
    End If

    ' How much compression occured?
    Dim e As ChilkatZipEntry2
    Set e = ZipFile.GetEntryByIndex(0)
    If (Not (e Is Nothing)) Then
        origSize = e.UncompressedLength
        compressedSize = e.CompressedLength
        ZipStatus.Caption = "Success." + vbCrLf + Str(origSize) + " bytes compressed to " + Str(compressedSize) + " bytes"
        Set e = Nothing
    End If
    
    ZipFile.CloseZip
    
    Set ZipFile = Nothing
    
End Sub

Private Sub Form_Load()
    OutputZip.Text = CurDir$ + "\outputFile.zip"
    
End Sub

    

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.