Need help with Binary files and data types in VB6

Reply

Join Date: Jul 2006
Posts: 11
Reputation: cyman73 is an unknown quantity at this point 
Solved Threads: 0
cyman73 cyman73 is offline Offline
Newbie Poster

Need help with Binary files and data types in VB6

 
0
  #1
Aug 1st, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

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

 
0
  #2
Aug 1st, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 11
Reputation: cyman73 is an unknown quantity at this point 
Solved Threads: 0
cyman73 cyman73 is offline Offline
Newbie Poster

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

 
0
  #3
Aug 4th, 2006
Deleted..
Please see below
Last edited by cyman73; Aug 4th, 2006 at 3:10 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 11
Reputation: cyman73 is an unknown quantity at this point 
Solved Threads: 0
cyman73 cyman73 is offline Offline
Newbie Poster

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

 
0
  #4
Aug 4th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 11
Reputation: cyman73 is an unknown quantity at this point 
Solved Threads: 0
cyman73 cyman73 is offline Offline
Newbie Poster

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

 
0
  #5
Aug 4th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 11
Reputation: cyman73 is an unknown quantity at this point 
Solved Threads: 0
cyman73 cyman73 is offline Offline
Newbie Poster

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

 
0
  #6
Aug 4th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC