 |
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

March 3rd, 2008, 06:37 PM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Manipulate numeric data in binary files
I have a binary file (written by a C++ app) that contains a numeric data field. The decimal value of the field is 6187 as displayed in an app GUI, however when I open the binary file in a hex editor, the field is shown as 2b 18 00 00.
When I convert 6187 to hex in a calculator, the result is 182b, so it is clear that the number is being stored as four bytes in reverse order (instead of 00 00 18 2b).
I'm working with VB6. I need to get the value out of the record, increment its value, and update the record with the new value. Is there a simple (straight-forward) way to do this?
Any help would be greatly appreciated.
|

March 4th, 2008, 07:07 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Hi there... why don't you just read the first byte, add 1 to it (as a byte number) and then store it again where it should (that can be a pain in the ass, since you have to write all the file to do that)..
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
|

March 4th, 2008, 05:52 PM
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Gonzalo, that would give trouble when there is a carry...
I think you will need to convert this to decimal (in Integer), increment it, then convert back to Least-Significant-Byte/Most-Significant-Byte, and write it back to the file.
So get the first value, then add the second value times 256 to it.
Then increment.
Then write the value Mod 255
Subtract the value Mod 255, then divide the results of that by 255, and write it.
|

March 4th, 2008, 09:24 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
You won't believe me Brian, but I was thinking in the carry a second before I wrote the post.. then I forget about it... damm...
Thanks Brian...
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
|

March 11th, 2008, 08:06 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
declare a variabile of type Long, and read that from the file:
Code:
Dim f As Integer
f = FreeFile
Open "c:\foo" For Binary Access Read As #f
Dim k As Long
Get f, ,k
debug.print k, "0x" & hex(k)
close f
and you'll see that you get 6187 0x182B as results, that is what you want
Increment k by 1, open the file as readwrite, and put back k
Code:
Open "c:\foo" For Binary Access Read Write As #f
k = k + 1
Put f, , k
Close f
"There are two ways to write error-free programs. Only the third one works."
Unknown
|

March 12th, 2008, 03:28 PM
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Quote:
quote:Originally posted by gbianchi
You wonât believe me Brian, but...
|
But, I do believe you. (Would it be too over the top to say, âGlad I could help carry the solution to the poster?â)
|

March 12th, 2008, 03:30 PM
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
I didn't realize that reading out of a file into a long handled the LSB-MSB order of things properly. That's a good thing to know. Kudos.
|

March 12th, 2008, 03:35 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
yeah Marco great solution..
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
|
|
 |