UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Edit Discussion
> FileToByteArray    
(Difference between revisions)
Revision as of 02:35, 12 May 2012
Jleach (Talk | contribs)

← Previous diff
Current revision
Jleach (Talk | contribs)
(added See Also: FileToString)
Line 1: Line 1:
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. 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]]
[code] [code]

Current revision

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

CODE

' 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
Thank you for your support!
This page has been accessed 383 times.  This page was last modified 02:36, 12 May 2012 by Jack Leach.   Disclaimers