Results 1 to 13 of 13

Thread: [RESOLVED] [ASK] Unicode : Read Binary file at MULTI spesific position

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    32

    Resolved [RESOLVED] [ASK] Unicode : Read Binary file at MULTI spesific position

    goooooood morning everyone !

    Hi, i have looking in this one for this prblem :

    http://www.vbforums.com/showthread.php?t=597679

    but, i little confuse when i modify some code like this :


    Open sFile For Binary Access Read As #2
    Get #2, 512, cb(0)
    Get #2, 1024, cb(1)
    Get #2, 2048, cb(2)
    Get #2, 3000, cb(3)
    Get #2, 4096, cb(4)
    Get #2, 5000, cb(5)
    Get #2, 6000, cb(6)
    Get #2, 7000, cb(7)
    Get #2, 8192, cb(8)
    Get #2, 9000, cb(9)
    Get #2, 10000, cb(10)
    Get #2, 11000, cb(11)
    Get #2, 12288, cb(12)
    Get #2, 13000, cb(13)
    Get #2, 14000, cb(14)
    Get #2, 15000, cb(15)
    Get #2, 16384, cb(16)
    Get #2, 17000, cb(17)
    Get #2, 18000, cb(18)
    Get #2, 19000, cb(19)
    Get #2, 20480, cb(20)
    Get #2, 21000, cb(21)
    Get #2, 22000, cb(22)
    Get #2, 23000, cb(23)
    Close #2

    is there anyone can help ?

    how can this function support Unicode Path ?

  2. #2
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: [ASK] Unicode : Read Binary file at MULTI spesific position

    So the problem exactly is?

    If it's Unicode path, then the link you posted gives you the solution. What's the problem ?
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    32

    Re: [ASK] Unicode : Read Binary file at MULTI spesific position

    the link that i give, it just solve single spesific binary read ...

    like :

    Code:
    Get #2, , Bin
    but it doesn't solve when the code have multi spesific binary need like :

    Code:
    Get #2, 512, cb(0)
    Get #2, 1024, cb(1)
    Get #2, 2048, cb(2)
    Get #2, 3000, cb(3)
    Get #2, 4096, cb(4)
    Get #2, 5000, cb(5)
    do you have any idea ?

  4. #4
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: [ASK] Unicode : Read Binary file at MULTI spesific position

    Get #2, 5000, cb(5)
    Get the is the name(keyword) of the statement. The #2 indicates a filenumber(#) and the specific filenumber(2). 5000 is the recnumber(byte location, 1 is the first byte). cb(n) is an array of type unknown, and acts as a buffer. The Get statement will 'calculate the length' of the buffer, and read that many bytes from the file starting at the recnumber(byte location), if possible(or stops when it reaches the end of file).

    For instance, in the thread you link there's a function called GetBin. To convert the statement I quote originally:

    vb Code:
    1. GetBin("filename", LenB(cp(5)), 5000)

    LenB(cp) would be the length in bytes of type cp. For a string it'd be the length of the string. All the types 'byte-usage requirements' are available in the help.

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    32

    Re: [ASK] Unicode : Read Binary file at MULTI spesific position

    in link that i give, it just solve this function :

    Code:
    Open sFile For Binary Access Read As #2
       Get #2, 512, cb(0)
    Close #2
    that i ask is,,
    How Can This Function Support the Unicode Filepath, and solve this function :

    Code:
    Open sFile For Binary Access Read As #2
      Get #2, 512, cb(0)
      Get #2, 1024, cb(1)
      Get #2, 2048, cb(2)
      Get #2, 3000, cb(3)
      Get #2, 4096, cb(4)
      Get #2, 5000, cb(5)
      Get #2, 6000, cb(6)
      Get #2, 7000, cb(7)
      Get #2, 8192, cb(8)
      Get #2, 9000, cb(9)
      Get #2, 10000, cb(10)
      Get #2, 11000, cb(11)
      Get #2, 12288, cb(12)
      Get #2, 13000, cb(13)
      Get #2, 14000, cb(14)
      Get #2, 15000, cb(15)
      Get #2, 16384, cb(16)
      Get #2, 17000, cb(17)
      Get #2, 18000, cb(18)
      Get #2, 19000, cb(19)
      Get #2, 20480, cb(20)
      Get #2, 21000, cb(21)
      Get #2, 22000, cb(22)
      Get #2, 23000, cb(23)
    Close #2
    this function has multi 'get' command isn't it ?

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [ASK] Unicode : Read Binary file at MULTI spesific position

    Just repeat the call to the GetBin Function with the appropriate arguments!
    Code:
    cb(0) = GetBin(sFile, LenB(cb(0)), 512)  ' equivalent to Get #2, 512, cb(0)
    cb(1) = GetBin(sFile, LenB(cb(1)), 1024) ' equivalent to Get #2, 1024, cb(1)
    cb(2) = GetBin(sFile, LenB(cb(2)), 2048) ' equivalent to Get #2, 2048, cb(2)
    .
    .
    etc
    The original GetBin code will probably need some alterations since it returns the sum of the data read (as a string value), not the data itself. Obviously it should return the same type as the array cb.

    Also, as LaVolpe points out, it does not use StartByte so the suggested change in Post #6 of the original thread should be implemented.
    Last edited by Doogle; Sep 12th, 2010 at 03:07 AM.

  7. #7
    Junior Member
    Join Date
    Jan 2010
    Location
    Bali, Indonesia
    Posts
    17

    Re: [ASK] Unicode : Read Binary file at MULTI spesific position

    it's an algorithm for generating a checksum of a file, isn't it?
    Last edited by Zeven; Sep 12th, 2010 at 12:29 PM.
    1# VB always true
    2# If VB false, back to statement 1# (VB always true)

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    32

    Lightbulb Re: [ASK] Unicode : Read Binary file at MULTI spesific position

    Quote Originally Posted by Doogle View Post
    Just repeat the call to the GetBin Function with the appropriate arguments!
    Code:
    cb(0) = GetBin(sFile, LenB(cb(0)), 512)  ' equivalent to Get #2, 512, cb(0)
    cb(1) = GetBin(sFile, LenB(cb(1)), 1024) ' equivalent to Get #2, 1024, cb(1)
    cb(2) = GetBin(sFile, LenB(cb(2)), 2048) ' equivalent to Get #2, 2048, cb(2)
    .
    .
    etc
    The original GetBin code will probably need some alterations since it returns the sum of the data read (as a string value), not the data itself. Obviously it should return the same type as the array cb.

    Also, as LaVolpe points out, it does not use StartByte so the suggested change in Post #6 of the original thread should be implemented.
    Voila ! why i can't miss that way ?

    but .. still little bit confuse.


    okay, this one is the complete one :

    Code:
    Private Function GetDNA(sFile As String) As String
        On Error GoTo ErrHandle
        
        Dim buff As String
        Dim cb(0 To 23) As Byte
        
        If GetInputState = 0 Then
         SetFileAtt sFile, &H80
         
        Open sFile For Binary Access Read As #2
            Get #2, 512, cb(0)
            Get #2, 1024, cb(1)
            Get #2, 2048, cb(2)
            Get #2, 3000, cb(3)
            Get #2, 4096, cb(4)
            Get #2, 5000, cb(5)
            Get #2, 6000, cb(6)
            Get #2, 7000, cb(7)
            Get #2, 8192, cb(8)
            Get #2, 9000, cb(9)
            Get #2, 10000, cb(10)
            Get #2, 11000, cb(11)
            Get #2, 12288, cb(12)
            Get #2, 13000, cb(13)
            Get #2, 14000, cb(14)
            Get #2, 15000, cb(15)
            Get #2, 16384, cb(16)
            Get #2, 17000, cb(17)
            Get #2, 18000, cb(18)
            Get #2, 19000, cb(19)
            Get #2, 20480, cb(20)
            Get #2, 21000, cb(21)
            Get #2, 22000, cb(22)
            Get #2, 23000, cb(23)
        Close #2
        buff$ = cb(0)
        
        buff$ = buff$ & cb(1)
        buff$ = buff$ & cb(2)
        buff$ = buff$ & cb(3)
        buff$ = buff$ & cb(4)
        buff$ = buff$ & cb(5)
        buff$ = buff$ & cb(6)
        buff$ = buff$ & cb(7)
        buff$ = buff$ & cb(8)
        buff$ = buff$ & cb(9)
        buff$ = buff$ & cb(10)
        buff$ = buff$ & cb(11)
        buff$ = buff$ & cb(12)
        buff$ = buff$ & cb(13)
        buff$ = buff$ & cb(14)
        buff$ = buff$ & cb(15)
        buff$ = buff$ & cb(16)
        buff$ = buff$ & cb(17)
        buff$ = buff$ & cb(18)
        buff$ = buff$ & cb(19)
        buff$ = buff$ & cb(20)
        buff$ = buff$ & cb(21)
        buff$ = buff$ & cb(22)
        buff$ = buff$ & cb(23)
        GetDNA = CRCFromString(buff)
        Exit Function
        End If
    ErrHandle:
        Close #2
        Exit Function
    End Function
    is there any solution for this one ?

  9. #9
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [ASK] Unicode : Read Binary file at MULTI spesific position

    I'm confused now. What's changed since you posted this:
    http://www.vbforums.com/showthread.php?t=599236 ?

  10. #10
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    280

    Re: [ASK] Unicode : Read Binary file at MULTI spesific position

    Actually I am a bit confused now too.

    Get #2, 512, cb(0)

    Wouldn't this line read file #2 from record number 512 to the end of the file into CB(0).

    Get #2, 1024, cb(1)
    Then this one would attempt to read file#2 to the end of the line into cb(1). But file#2 would already be at EOF soit would fail. Could this be the OP's problem and he needs to reset the file pointer between reads?
    Slower than a crippled Vista
    More buggy than a fresh XP install
    Look! Down the road, some 50 miles behind the drunken snail.
    It's Ubuntu!

  11. #11
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: [ASK] Unicode : Read Binary file at MULTI spesific position

    AsmIsCool, Get has no notions of "lines". It will of course stop at the end of the file.

    The amount of data to be read is determined by the size of the buffer passed to Get, which in that case would be cb(0) or cb(1), the third parameter. If the buffer size plus start position(the 2nd parameter; right after file number) goes beyond the EOF, then it will only read until the EOF.

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [ASK] Unicode : Read Binary file at MULTI spesific position

    mozzart, to summarize a couple things

    1) your most recent code (post#8) can have issues with unicode files and/or path names

    2) As FireXtol explained, what variable type you pass to GET statement determines how many bytes read. So in your posted code, you are reading a single byte from various file positions. What if you have a small file, the final read-attempts should fail & return 0 in the related cb() positions.

    3) You can do this a bit more efficiently. If you are only interested in approx the 1st 23kb of the file, declare an array of 23kb, read 23kb, then build your buffer off the related array elements & get your CRC value.
    Code:
     Dim cb(1 to 2300)
    ' open file
       Get #2, 1, cb()
    ' close file
    ' build buffer, i..e, 
        buff$ = cb(512)
        buff$ = buff$ & cb(1024)
        ' etc
    ' get your crc
    Last edited by LaVolpe; Sep 17th, 2010 at 02:17 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  13. #13

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    32

    Unhappy Re: [ASK] Unicode : Read Binary file at MULTI spesific position

    Quote Originally Posted by LaVolpe View Post
    mozzart, to summarize a couple things

    1) your most recent code (post#8) can have issues with unicode files and/or path names

    2) As FireXtol explained, what variable type you pass to GET statement determines how many bytes read. So in your posted code, you are reading a single byte from various file positions. What if you have a small file, the final read-attempts should fail & return 0 in the related cb() positions.

    3) You can do this a bit more efficiently. If you are only interested in approx the 1st 23kb of the file, declare an array of 23kb, read 23kb, then build your buffer off the related array elements & get your CRC value.
    Code:
     Dim cb(1 to 2300)
    ' open file
       Get #2, 1, cb()
    ' close file
    ' build buffer, i..e, 
        buff$ = cb(512)
        buff$ = buff$ & cb(1024)
        ' etc
    ' get your crc
    hmm.i'm sorry if i re-post my question in this thread.

    but i got a problem when i using API read function.

    it has different result when i compare with Open ... Get .. Close function



    have you found a problem like me ?

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