Results 1 to 7 of 7

Thread: [RESOLVED] Code Help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Resolved [RESOLVED] Code Help

    Hello, I'm trying to write a code by working off of a source I've been looking at, but I really have no idea what I'm doing. I would appreciate it if somebody could help me correct my code and possibly explain to me why it was not working and answer the questions i have posted in the code, or just refer me to a tutorial that could help me, Thank you .

    My code is:
    Code:
    Dim strjpg as string
    Dim strjpgcode as string
    Dim strsize as string
    Dim strtarget as string
    strsize = 20480       'what is this for? why is it significant?
    strjpg = Text1.Text  
    Open strjpg For Binary As #1
    strjpgcode = Input$(LOF(1), 1)  'what is LOF(1),1) ?
    strcount = Mid(strjpgcode, 1, strsize) 
    Close #1
    Open strtarget For Output As #1
            Print #1, strcount
          Close #1
    End Sub
    This is supposed to take a jpg and then insert the hex into another jpg file with nothing in it, and basically make it the same. But for some reason (i think it has to do with the strsize) the target picture is missing it's bottom half. Thanks for any help!

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Re: Code Help

    *BUMP* Can anybody please help me with this?

  3. #3
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Code Help

    Welcome to the forums

    As you seem to be making a copy of the first file why not use the below?

    VB Code:
    1. FileCopy "C:\File1.jpg", "File2.jpg"

    I modified your code so it will copy the entire file.

    VB Code:
    1. Dim strjpg As String
    2. Dim strjpgcode As String
    3. Dim strsize As Double
    4. Dim strtarget As String
    5. Dim strcount As String
    6.  
    7. strjpg = Text1.Text
    8.  
    9. Open strjpg For Binary As #1
    10. 'LOF returns the size of the file you want to copy.
    11. strsize = LOF(1) '20480       'what is this for? why is it significant?
    12.  
    13. ' Input$(LOF(1), 1)  returns the entire file into a string
    14. strjpgcode = Input$(LOF(1), 1)  'what is LOF(1),1) ?
    15. strcount = Mid(strjpgcode, 1, strsize)
    16. Close #1
    17.  
    18. Open strtarget For Output As #1
    19.         Print #1, strcount
    20.       Close #1

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Re: Code Help

    Thank you! The reason I'm doing it that way is because I am actually trying to take this from two different files, and then put it into one file. I understand what I'm doing now, but I still can't get this new code to work.

    Code:
    Dim strjpg As String
    Dim strjpgcode As String
    Dim strsize As String
    Dim strrar As String
    Dim strrarcode As String
    Dim strtarget As String
    Dim strtargetcode As String
    Dim strsize2 As String
    Dim strcount As String
    Dim strcount2 As String
    
    strjpg = Text1.Text
    Open strjpg For Binary As #1
    
    strsize = LOF(1)
    
    
    strjpgcode = Input$(LOF(1), 1)
    strcount = Mid(strjpgcode, 1, strsize)
    Close #1
    strtarget = Text3.Text
    Open strtarget For Output As #1
            Print #1, strcount
          Close #1
          strrar = Text2.Text
          Open strrar For Binary As #2
          strsize2 = LOF(2)
          strrarcode = Input$(LOF(2), 2)
          strcount2 = Mid(strrarcode, 1, strsize2)
          Close #2
          Open strtarget For Output As #2
          Print #2, strcount2
          Close #2
          
    
    End Sub
    What ends up happening is the second file that I am copying completely overwrites the first. I am trying to just add the second file to the end of the first one. Can you possibly help me with this? I'll continue to try while I wait for a response. Thanks again for all your help!

  5. #5

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    122

    Re: Code Help

    Thank you gavio! That's exactly what I needed, it works perfectly now. Thanks to everybody that helped me!

  7. #7

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