Results 1 to 3 of 3

Thread: Writing A File (Harder Question)

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    HI,

    I need help!
    I need the code to do this..

    Write 2 pictures
    to a .inx file.

    C:\win\test1.bmp
    c:\win\test2.bmp

    output:

    c:\win\test.inx


    And then I need the code to
    extract the file..

    It would be so helpfull ..
    I cant figure it out for the
    life of me!

    Thankyou so much!


  2. #2
    Guest
    open them both for binary access...
    open the destination file as append...
    write a long integer to the start of the file with the length of the first picture in bytes, and then add both the pictures.

    when you need to read them out again, just get the long integer out first, and then read that many bytes (then you'll have the first picture), then the rest will be entirely taken over by the second picture.

    Phew!

  3. #3
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    I was writing exactly what wossname suggested, as he suggested it, so here ya go.

    Code:
    Option Explicit
    
    Private Sub joinPictures(strPic1 As String, strPic2 As String, strNewFile As String)
        Dim btemp() As Byte
        
        Open strNewFile For Binary As #1
        'put the file lengths in the file
        Put #1, , FileLen(strPic1) & "," & FileLen(strPic2) & vbCrLf
        
        'open the first picture for binary
        Open strPic1 For Binary As #2
        'size the array to the size of the file
        ReDim btemp(LOF(2) - 1) As Byte
        'get the data
        Get #2, , btemp
        'put the data
        Put #1, , btemp
        Close #2
        
        Open strPic2 For Binary As #2
        ReDim btemp(LOF(2) - 1) As Byte
        Get #2, , btemp
        Put #1, , btemp
        Close #2
        
        Close #1
        
    End Sub
    
    Private Sub cmdJoin_Click()
        joinPictures txtInput1, txtInput2, txtOutput
        MsgBox "Done!"
    End Sub
    
    
    Private Sub splitPictures(strPic1 As String, strPic2 As String, strJoinedFile As String)
        Dim strSize1 As String, strSize2 As String
        Dim strTemp As String
        Dim ip As Long
        Dim btemp() As Byte
        
        'open the file to get the sizes of the pictures
        Open strJoinedFile For Input As #1
        Line Input #1, strTemp
        Close #1
        
        'get teh sizes from the temp string
        ip = InStr(1, strTemp, ",")
        strSize1 = Mid$(strTemp, 1, ip - 1)
        strSize2 = Mid$(strTemp, ip + 1)
        
        Open strJoinedFile For Binary As #1
        
        'redim the array to teh size of the first picture
        ReDim btemp(CLng(strSize1) - 1) As Byte
        Open strPic1 For Binary As #2
        'get the data starting from after the length data
        Get #1, Len(strTemp) + 3, btemp
        'put the data
        Put #2, , btemp
        Close #2
        
        ReDim btemp(CLng(strSize2) - 1) As Byte
        Open strPic2 For Binary As #2
        Get #1, , btemp
        Put #2, , btemp
        Close #2
        
        Close #1
        
    End Sub
    
    Private Sub cmdSplit_Click()
        splitPictures txtInput1, txtInput2, txtOutput
        MsgBox "Done!"
    End Sub
    Iain, thats with an i by the way!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width