Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
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
 
Old March 3rd, 2008, 06:37 PM
Authorized User
 
Join Date: Jun 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
 
Old March 4th, 2008, 07:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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
================================================== =========
 
Old March 4th, 2008, 05:52 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
 
Old March 4th, 2008, 09:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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
================================================== =========
 
Old March 11th, 2008, 08:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default


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
 
Old March 12th, 2008, 03:28 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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?”)
 
Old March 12th, 2008, 03:30 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
 
Old March 12th, 2008, 03:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
database to excel manipulate data weazy Excel VBA 1 June 9th, 2006 12:07 PM
Binary files MAXhYpe C# 0 November 2nd, 2004 04:42 AM
Reading from Binary Files jschmi J2EE 0 October 5th, 2004 01:09 AM
Writing data to binary files maniac_ie C++ Programming 2 February 24th, 2004 12:30 PM
manipulate data returned using client script alyeng2000 Classic ASP Databases 5 December 9th, 2003 01:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.