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:

Dim iFileNo as Integer
Dim bVer as Byte
Dim lNumberOfFiles as Long
Dim lBufferSize as Long
Dim tBuffer as String

FileNum = FreeFile
Open tBinaryFilepath For Binary Access Read Lock Read Write As #FileNum
Get #FileNum, , iFileNo
Get #FileNum, , bVer
Get #FileNum, , lNumberOfFiles
Get #FileNum, , lBufferSize
tBuffer = String(lBufferSize, "")
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.

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?

Deleted..
Please see below

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.

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.

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

Dim tNameBin as String
Dim lBufferSize as Long
:
'Name Field
tNameBin = "UserName" 
lBufferSize = Len(tNameBin) 
Put #TempFileNum, , lBufferSize
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.