Results 1 to 7 of 7

Thread: Read files in binary FAST

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    115
    Ok I am writing a program, and it reads binary files, but using vb6's normal file thing 'Open file for Binary as filenum' and the function 'input(1, 1)' well its way too slow. It takes like a whole second to read a 2k file. I need some scripting or API to make it read faster. so see if you can help.
    Vuen

  2. #2
    Open the file in binary
    Get the length of file in bytes
    dim avariable that many bytes big
    do this:
    input(filenumber,'avariable that many bytes big')
    instead of this:
    input(1,1) 'this inputs one byte at a time! That's Slow


    Now hit the manuals boy!

    [Edited by 23yearsofit on 03-23-2000 at 12:33 PM]

  3. #3
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Sedgefield
    Posts
    337
    Read it all in one go into a Byte() array - much faster!

    Code:
        Dim myData() As Byte
        i = FreeFile
        Open "C:\Temp\myFile.def" For Binary Access Write As #i
        Put #i, , myData
        Close #i
    Hope that helps



    Dan

  4. #4
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Sedgefield
    Posts
    337
    Sorry...you should use Get not Put.....

    Code:
        Dim myData() As Byte
    
        i = FreeFile
        Open "C:\Temp\myFile.def" For Binary Access Read As #i
        Get #i, , myData
        Close #i
    You can use FileLen(myFile.def) to find the size of the file if you want and then Dim myData to the right size...



    Dan

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    115

    COOL! Ok.

    OK cool I got it. Thanx guys!
    Don't worry I'll write a sub that takes one off the string every time don't worry I'll get it easily.
    You don't know how important this is guys thanx guys.

    Wow you guys get a lot of posts I posted this 10 hours ago and its way way down the list...

    If you want to see my work just go to http://zap.to/Vuen the botmaker is what I'm working on, if any of you have played OMF2097 well this is to make your own robots for the game. Its about half done thats why its version 0.5 thats released right now see the problem was the image previewer. It was... well slow.

    Well nuts. I have a bigger problem now. I have a big geography test tomorrow (grade 9) but my problem is I will stay up all night making this work and then freak out and not be able to sleep and then I will be all screwed for the test.
    Vuen

  6. #6
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Super fast way to read with binary

    I dont know if this is a good way to do this.. but, if u wanna read something into a textbox then just do.

    Dim AGET as string * 50000

    open myfile for binary as #1
    do
    get 1,,aget
    text1.text = text1.text & aget
    loop until eof(1)
    close #1

  7. #7
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    invitro,

    I dont know if this is a good way to do this..


    I would say it's not a particullaly good way
    becasuse it's wasting resources and processor time.
    (not to mention using a fixed file number)





    Code:
        Dim strTemp as String
    
        i = FreeFile
        Open "C:\Temp\myFile.def" For Binary Access Read As #i
        strTemp = space(LOF(i)
        Get #i, , strTemp
        Close #i
    
       Text1.text = strtemp
    Mark
    -------------------

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