Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default Import binary file and convert to HEX data

I want to work with files made from a EPROM programmer. The file types
are binary and ASCII HEX. The HEX file I can import into excel with no
problem. I would like a macro that can convert the binary file to hex
data so I can work with it in excel. I searched the web but did not
find what I need. Too much non related info to sift through. I have
Excel 97. Any ideas?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Import binary file and convert to HEX data

This program writes the binary number 0 - 255 to a file. Then closes the
file and reads the file into the worksheet. I needed to write binary data so
I could test the read function. Data is stored in worksheet as two byte
character string. I had to format the wrok sheet as text before program
worked correctly. I can change the format if necessary to any format you
would like.

I didn't use the HEX function because it doesn't display the data as two
bytes. Number 0 to F with the hex function is only display as a single
character.

Sub BinaryStream()

Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s

Filename = "c:\temp\binary.txt"

Set fs = CreateObject("Scripting.FileSystemObject")
fs.CreateTextFile Filename 'Create a file

Set f = fs.GetFile(Filename)

Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
For Count = 0 To 255
ts.Write Chr(Count)
Next Count
ts.Close

Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
ColumnCount = 1
RowCount = 1
Do While ts.atendofstream = False
Hexbyte = Asc(ts.Read(1))
nibble = Int(Hexbyte / 16)
If nibble <= 9 Then
Hexupper = Chr(Asc("0") + nibble)
Else
Hexupper = Chr(Asc("A") + (nibble - 10))
End If
nibble = Hexbyte Mod 16
If nibble <= 9 Then
HEXlower = Chr(Asc("0") + nibble)
Else
HEXlower = Chr(Asc("A") + (nibble - 10))
End If
Cells(RowCount, ColumnCount) = _
Hexupper & HEXlower
ColumnCount = ColumnCount + 1
If ColumnCount 16 Then
ColumnCount = 1
RowCount = RowCount + 1
End If
Loop

ts.Close
End Sub


"Fan924" wrote:

I want to work with files made from a EPROM programmer. The file types
are binary and ASCII HEX. The HEX file I can import into excel with no
problem. I would like a macro that can convert the binary file to hex
data so I can work with it in excel. I searched the web but did not
find what I need. Too much non related info to sift through. I have
Excel 97. Any ideas?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default Import binary file and convert to HEX data

Hi Joel. Thanks a million. It worked great. I learned a lot just
trying to modity it for may application. Now, I am tryig to mofiy your
binary file read code to also read a hex file.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert binary to decimal Krishnakanth Excel Discussion (Misc queries) 2 May 7th 08 02:56 PM
Convert Binary to Decimal using IF and Sum Functions? YourFriendlyTechGuy Excel Worksheet Functions 3 January 31st 07 01:06 AM
Convert Binary to Hex Chipmunk Excel Programming 9 August 24th 06 12:53 PM
Convert SpreadsheetML to binary .xls [email protected] Excel Programming 0 March 17th 06 05:45 PM
How do I convert cell contents that are Hex to binary? KarenSue33 Excel Worksheet Functions 1 February 21st 05 05:41 PM


All times are GMT +1. The time now is 12:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"