944,189 Members | Top Members by Rank

Ad:
Jan 2nd, 2006
0

Reading binary data from a file and writing it

Expand Post »
In Visual Basic 6 I have written a program to read and write to a file. It works fine. Now I have to do the same for binary data since the information I write to the file has end-of-line and return characters. For instance, when I write to the file, the data looks like this:

"3
34"

Because there is a break in the data. In debug mode, the text data has two boxes where the end-of-line and return characters go.

Anyway, does anyone have any example code of binary level reading and writing to and from a file?
Similar Threads
Reputation Points: 17
Solved Threads: 0
Junior Poster
complete is offline Offline
147 posts
since Dec 2005
Jan 4th, 2006
0

Re: Reading binary data from a file and writing it

The character codes for that are vbcr and vblf (also vbcrlf) which translate to chr(13) and chr(10) (those are carriage return and line feed). So, if it would be easier for you to merely check for an occurance of either of those in a string using instr, and replacing the offending character with the replace function, that might be an easier solution for you. However, if you want to leave the file completely unchanged, and merely write the file as it is with binary:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim B() As Byte
  2. Dim srcFile as string
  3. dim destFile as string
  4.  
  5. ' /* Change This To your File */
  6. srcFile = "c:\somefile.exe"
  7. destFile = "c:\destination.exe"
  8.  
  9. Open srcFile For Binary Access Read As #1
  10. ReDim B(LOF(1) - 1)
  11. Get #1, , B
  12. Close #1
  13.  
  14. open destfile for binary access write as #1
  15. put #1, , B
  16. close #1

Let me know what you come up with.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004

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: using the clipboard
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: RmDir and MsChart Have Problems in XP -Pls Help





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


Follow us on Twitter


© 2011 DaniWeb® LLC