Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binary to text conversion?

Status
Not open for further replies.

hensods

Programmer
Oct 29, 2003
3
US
I have a .bin file that I need to get some information out of. I need to be able to convert it into either decimal values, or text. I have another program that can read this, but I need to be able to convert it myself, and use the values that are in the file. Does anybody have any clue how to do this? Let me know if you need more info.

If you would like me to send you the file so you can look at it just email me at dhenson@uss.com
 
Make a copy of the file. Do not do this with the original file because you could corrupt it.

Here is some code that will read the first 1000 bytes of a file named temp.exe and write the output to a file named test.txt.

Dim MyByte As Byte
Dim MyRecNumber As Integer
Dim MyString As String

Open "C:\Temp.exe" For Binary As 1
Open "C:\Test.TXT" For Output As 2

MyRecNumber = 1
Do
Get #1, MyRecNumber, MyByte
MyString = Str(MyByte)
MyString = Space$(4 - Len(MyString)) & MyString
Print #2, MyString;
If Int(MyRecNumber / 16) = MyRecNumber / 16 Then
Print #2, vbCrLf;
End If
MyRecNumber = MyRecNumber + 1
Loop Until MyRecNumber = 1000

Close 1, 2


One thing to remember about Binary file access. If you read past the end of the file you will not get and end of file error, the size of the file will just be expanded to fit. You will need to determine the size of the file before you start accessing it and YOU will be responsible for not reading past the end of the file.

And I cannot emphesize enough that you sould work with a copy of the file, not the original. It's really easy to screw up the file doing this.


-Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top