VB and VBA Users Source Code: Reading the contents of any file into a byte array
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Reading the contents of any file into a byte array
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Friday, August 24, 2001
Hits:
741
Category:
Files/Directories/IO
Article:
The following code reads any type of file into a byte array: Option Explicit 'Purpose : Opens and reads a binary file into a byte array. 'Inputs : sFileName The file name to read the contents of. 'Outputs : Returns the contents of the file as a one based 1d byte array, else returns ' True on error. 'Author : Andrew Baker 'Date : 25/11/2000 03:17 'Notes : The files can be of any type. 'Revisions : Function FilesBinaryRead(ByVal sFileName As String) As Variant Dim abBuffer() As Byte, ihwndFile As Integer On Error GoTo ErrFailed 'Open file ihwndFile = FreeFile Open sFileName For Binary Access Read As #ihwndFile 'Size the array to hold the file contents ReDim abBuffer(1 To LOF(ihwndFile)) Get #ihwndFile, , abBuffer Close #ihwndFile 'Return the contents of the file FilesBinaryRead = abBuffer Exit Function ErrFailed: 'Failed to open the file Debug.Print "Error in FilesBinaryRead: " & Err.Description Close #ihwndFile FilesBinaryRead = True End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder