|
-
Sep 10th, 2010, 08:18 PM
#1
Thread Starter
Member
[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 ?
-
Sep 11th, 2010, 04:49 AM
#2
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.

-
Sep 11th, 2010, 11:23 AM
#3
Thread Starter
Member
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 ?
-
Sep 11th, 2010, 05:04 PM
#4
Re: [ASK] Unicode : Read Binary file at MULTI spesific position
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.
Last edited by FireXtol; Sep 11th, 2010 at 05:07 PM.
Software I use and highly recommend: Opera, Miranda IM, Peerblock, Winamp, Unlocker Assistant, JoyToKey, Virtual CloneDrive, Secunia PSI, ExplorerXP, GOM Player, Real Alternative, Quicktime Alternative,Sumatra PDF, and non-freeware: Photoshop and VB6( ).
My codebank: AllRGB, Rounded Rectangle(math), Binary Server, Buddy Paint, LoadPictureGDI+, System GUID/Volume Serial, HexToAsc, List all processes and their paths, quasiString matching
Strings(search, extraction, retrieval etc): Retrieve BBCode Link from HTML, RemoveBetween ()'s, strFindBetween(str1,str2), Insert text in HTML, HTML - GetSpanByID
-
Sep 11th, 2010, 07:14 PM
#5
Thread Starter
Member
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 ?
-
Sep 12th, 2010, 01:19 AM
#6
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.
-
Sep 12th, 2010, 12:12 PM
#7
Junior Member
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) 
-
Sep 13th, 2010, 06:37 AM
#8
Thread Starter
Member
Re: [ASK] Unicode : Read Binary file at MULTI spesific position
 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. 
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 ?
-
Sep 13th, 2010, 06:54 AM
#9
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 ?
-
Sep 17th, 2010, 10:08 AM
#10
Hyperactive Member
Re: [ASK] Unicode : Read Binary file at MULTI spesific position
Actually I am a bit confused now too.
Wouldn't this line read file #2 from record number 512 to the end of the file into CB(0).
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!
-
Sep 17th, 2010, 11:30 AM
#11
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.
Software I use and highly recommend: Opera, Miranda IM, Peerblock, Winamp, Unlocker Assistant, JoyToKey, Virtual CloneDrive, Secunia PSI, ExplorerXP, GOM Player, Real Alternative, Quicktime Alternative,Sumatra PDF, and non-freeware: Photoshop and VB6( ).
My codebank: AllRGB, Rounded Rectangle(math), Binary Server, Buddy Paint, LoadPictureGDI+, System GUID/Volume Serial, HexToAsc, List all processes and their paths, quasiString matching
Strings(search, extraction, retrieval etc): Retrieve BBCode Link from HTML, RemoveBetween ()'s, strFindBetween(str1,str2), Insert text in HTML, HTML - GetSpanByID
-
Sep 17th, 2010, 02:14 PM
#12
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.
-
Sep 18th, 2010, 10:21 AM
#13
Thread Starter
Member
Re: [ASK] Unicode : Read Binary file at MULTI spesific position
 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. 
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|