• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 52
  • Last Modified:

Seeking an EXPLANATION of 4 lines of Ron deBruin's code - which works very well, but I dont understand its notation

I am using code on a page of Ron deBruin's to move files into a zip folder.
@: https://www.rondebruin.nl/win/s7/win001.htm

Although it works very well for me, I cant understand this code that (successfully) creates a new ZipFolder, with the strName I provide (sPath )

Sub NewZip(sPath)
'Create empty Zip File
    If Len(Dir(sPath)) > 0 Then Kill sPath
    Open sPath For Output As #1    'this code
    Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
    Close #1
End Sub

Can someone explain the notation and how it works, please?
I write vba, but never in that notation

  • 2
1 Solution
Open sPath For Output As #1 - opens a file for writing, #1 is the alias
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0) - writes the data to the file
Close #1 - closes the file
Bill PrewCommented:
If Len(Dir(sPath)) > 0 Then Kill sPath

Uses the Dir() function to determine if the file already exists, and if it does then deletes (Kill) it.

Open sPath For Output As #1

Opens the file for writing as handle #1.

Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)

Prints the standard header signature for an empty PKZIP archive file.  This will later change to Chr$(80) & Chr$(75) & Chr$(3) & Chr$(4) when data is placed in the archive.

Close #1

Closes file handle #1 writing all data to disk.

You can dig deeper into any of the VBA functions and statements that are not familiar at these two references:

And a decent intro to the basic file I/O statements can be found here:

And you can learn way more info on the ZIP file format than you ever wanted to know at these (search the first for "50 4B 05 06" without the quotes):

Hope this helps.

Kelvin4Author Commented:
Thanks for a comprehensive explanation and references
Bill PrewCommented:
Welcome, glad that helped.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now