|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Extracting bytes from a fileHello!
Does somebody know how I can extract a byte "section" of file, when I know the byte start position and the length of bytes that should be extracted? Hans "Hans Achim" <h.ac***@gmx.de> wrote in message You could use Open/Seek/Get statements. Example:news:%23Sfx4xQ5JHA.1712@TK2MSFTNGP03.phx.gbl... > Hello! > > Does somebody know how I can extract a byte "section" of file, when I know > the byte start position and the length of bytes that should be extracted? Dim f As Integer Dim b() As Byte ReDim b(1 To 5) ' Get 5 Bytes f = FreeFile Open "C:\Test\Test.txt" For Binary As f Seek f, 100 ' Start from the 100th byte(base 1) Get f, , b Close f Use this hex editor to verify what you are doing: http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm "Hans Achim" <h.ac***@gmx.de> wrote The Get command allows you to specify where to start reading:> Hello! > > Does somebody know how I can extract a byte "section" of file, when I > know the byte start position and the length of bytes that should be > extracted? <air code warning...> ' Suppose you want 10 bytes from offset 200 Dim data(1 to 10) As Byte Open "..." For Binary As 1 Get #1, 200, data Close 1 The data array will contain 10 bytes, from offset 200 to 209. (The first byte of a file is position 1) HTH LFS |
|||||||||||||||||||||||