944,041 Members | Top Members by Rank

Ad:
Aug 1st, 2006
0

Need help with Binary files and data types in VB6

Expand Post »
Hello all,

I am reading (get) and writing (put) values from multiple binary files.

I first have to copy a binary file file1.bin to file2.bin and then I append 1 record to file2.bin.

My problem is when I read the following code I am not getting the values I expect:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim iFileNo as Integer
  2. Dim bVer as Byte
  3. Dim lNumberOfFiles as Long
  4. Dim lBufferSize as Long
  5. Dim tBuffer as String
  6.  
  7. FileNum = FreeFile
  8. Open tBinaryFilepath For Binary Access Read Lock Read Write As #FileNum
  9. Get #FileNum, , iFileNo
  10. Get #FileNum, , bVer
  11. Get #FileNum, , lNumberOfFiles
  12. Get #FileNum, , lBufferSize
  13. tBuffer = String(lBufferSize, "")
  14. Get #FileNum, , tBuffer


The only value that is correct is iFileNo. Everything after that is incorrect. For instance bVer should be 1 but comes out as 0. lNumber of Files should be 70 but comes out as 6816000, etc

Any help with this matter is greatly appreciated.

Thank you.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyman73 is offline Offline
11 posts
since Jul 2006
Aug 1st, 2006
0

Re: Need help with Binary files and data types in VB6

I noticed there is no loop here, so I'm guessing that was excluded from the excerpt, OR you are only reading that info once..... is it possible for you attach the project along with a sample .bin file that you have so that I can trace through the code?
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Aug 4th, 2006
0

Re: Need help with Binary files and data types in VB6

Deleted..
Please see below
Last edited by cyman73; Aug 4th, 2006 at 3:10 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyman73 is offline Offline
11 posts
since Jul 2006
Aug 4th, 2006
0

Re: Need help with Binary files and data types in VB6

Hey Comatose,

I do have a loop, but did not include in my example.

I used a hex editor to see exactly what the binary file contained.

Apparently, even if the first value was written as an integer in delphi 4 bytes, I had to use a long in VB6 to capture all 4 bytes. So now I figured out what I need to do to make it work. I am not sure I fully understand it though.

Here is what the first few fields look like according to the hex editor
39 1B 00 00 01 46 ...
__________ __ __


Thank you.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyman73 is offline Offline
11 posts
since Jul 2006
Aug 4th, 2006
0

Re: Need help with Binary files and data types in VB6

Follow up issue,
How can I write string contents to a binary file that would not be visible in a Hex editor as text?

Maybe I need to write as binary data? How does one convert a string to hex or binary?

Thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyman73 is offline Offline
11 posts
since Jul 2006
Aug 4th, 2006
0

Re: Need help with Binary files and data types in VB6

Follow up to my Binary file problem...

Hello all,
I am trying to write a string preceded by a length field in a binary file
Here is an example

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim tNameBin as String
  2. Dim lBufferSize as Long
  3. :
  4. 'Name Field
  5. tNameBin = "UserName"
  6. lBufferSize = Len(tNameBin)
  7. Put #TempFileNum, , lBufferSize
  8. Put #TempFileNum, , tNameBin

I am using a Hex editor to view the binary file.
After the first Put statement I see the following
08 00 00 00 ....

After the second Put statement I see the following
08 00 00 00 08 00 08 00 55 73 65 72 4E 61 6D ........UserName

My problem is that I see an extra 4 bytes of stuff preceding UserName, above in Bold. I do not want the extra bytes because they are messing up my binary file.

Any ideas are greatly appreciated.
Thank you.
Last edited by cyman73; Aug 4th, 2006 at 9:25 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyman73 is offline Offline
11 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB source code for Internet base webcam
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Novice help appreciated please





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC