Tim Hastings - NonHostile (because there's no need)

Weblog and collection of geeky articles.

  Home :: Who? :: Contact :: Links :: Subscribe subscribe
Thomas Andrew StaglesAbigail's ChristeningAn Afternoon in the Sun


Nothing radical here, but handy routines.

    Public Sub ReadByteArray(ByVal strPath As String, ByRef arrData() As Byte)

        Dim lngFile As Long

        ' open the file
        lngFile = FreeFile
        Open strPath For Binary Access Read As lngFile

        ' allocate enough memory to read file in one go
        ReDim arrData(1 To LOF(lngFile)) As Byte

        ' read blob
        Get lngFile, , arrData
        
        ' close file
        Close lngFile
       
    End Sub

     

    Private Sub WriteByteArray(ByVal strPath As String, ByRef arrData() As Byte)

        Dim lngFile As Long
       
        ' open the file
        lngFile = FreeFile()
        Open strPath For Binary Access Write As lngFile
       
        ' write blob
        Put lngFile, , arrData
       
        ' close file
        Close lngFile

    End Sub

     


2 comments, Visual Basic 6, Monday, April 5, 2004 09:01

Timeline Navigation for Visual Basic 6 posts
VB6: Free, Easy and Quick Base64 Encoding and Decoding in Visual Basic (made 22 minutes later)
VB6: Read and Write Byte Arrays to Files in Visual Basic (Code Library) (this post, made Monday, April 5, 2004 09:01)
VB6: Strategies for Indexing Elements of a Large XML DOM in Visual Basic (made 1 week earlier)


Comments
does this work with vb2008?

Posted by: jake strong on Friday, August 28, 2009 20:40
any1?

Posted by: jake strong on Friday, August 28, 2009 21:01

Post a Comment
Name:  Home page and email address are optional.
  Email addresses will not be displayed or spammed!
Remember these details
Email:
Home Page:
Comment:
Comments cannot contain HTML, URLs will be formatted into hyperlinks.
I reserve the right to remove any comments for any reason.