Binary Files

File Access

First, lets remind ourselves of how we access files in VB. The first step is to get a free file number using the FreeFile method. We then use the Open statement to open the file, specifying any options we want:

nFileNum = FreeFile
Open sFile For Binary Access Write Lock Read Write As #nFileNum

In this case, we open the file specified in sFile for binary write access (Binary Access Write), and prevent the file from being read and modified by other programs (Lock Read Write).

We would then read or write to the file as necessary, and when finished call the Close method:

Close #nFileNum

Now that we've quickly reminded ourselves of how file access works, we can get on to outputting a binary file.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint Exupéry