UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> FileToByteArray    

This function uses simple VBA IO to load a binary file into a byte array. Add error handling and file path validation as you wish.

See Also: FileToString


' FileToByteArray
' http://www.utteraccess.com/wiki/index.php/FileToByteArray
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
' You are free to use this code in any application,
' provided this notice is left unchanged.
' rev  date                          brief descripton
' 1.0  2012-05-11
Public Function FileToByteArray(FilePath As String) As Byte()
 'add error handling as required
 'add path validation as required
 Dim FileNum As Integer
 Dim Ret() As Byte
 FileNum = FreeFile
 Open FilePath For Binary Access Read As #FileNum
   ReDim Ret(LOF(FileNum) - 1) As Byte
   Get FileNum, , Ret
 Close #FileNum
 FileToByteArray = Ret
End Function

Creative Commons License
FileToByteArray by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search

Thank you for your support!
This page has been accessed 3,809 times.  This page was last modified 02:36, 12 May 2012 by Jack Leach.   Disclaimers