[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 ? :cry:
how can this function support Unicode Path ?:confused:
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 ?
Re: [ASK] Unicode : Read Binary file at MULTI spesific position
the link that i give, it just solve single spesific binary read ...
like :
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 ? :D
Re: [ASK] Unicode : Read Binary file at MULTI spesific position
Quote:
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:
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.
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 ? :confused:
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.
Re: [ASK] Unicode : Read Binary file at MULTI spesific position
it's an algorithm for generating a checksum of a file, isn't it?
Re: [ASK] Unicode : Read Binary file at MULTI spesific position
Quote:
Originally Posted by
Doogle
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. :lol:
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 ? :thumb:
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 ?
Re: [ASK] Unicode : Read Binary file at MULTI spesific position
Actually I am a bit confused now too.
Quote:
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).
Quote:
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?
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.
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
Re: [ASK] Unicode : Read Binary file at MULTI spesific position
Quote:
Originally Posted by
LaVolpe
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. :cry:
but i got a problem when i using API read function.
it has different result when i compare with Open ... Get .. Close function
:confused:
have you found a problem like me ?