Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 8
Default Converting hex to ascii

How do I convert a hex byte into an ascii character? I'll take an
excel formula or VB code. Either way would be fine. I could not find
an excel function to do this. I appreciate any help submitted. Thank
you.

tom
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Converting hex to ascii

It's confusing to say "hex byte" because that's mixing presentation with
storage. A Byte is a Byte and can be presented as decimal, hexadecimal,
binary, etc...

So, by Hex Byte I assume you actually mean hex string.

The first is Byte to Ascii, the secon is HexString to Ascii.

Sub test()
Dim byt As Byte, str As String

byt = &H41 'A
Debug.Print Chr(byt)

str = "41"
Debug.Print Chr("&H" & str)
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Tom" wrote in message
om...
How do I convert a hex byte into an ascii character? I'll take an
excel formula or VB code. Either way would be fine. I could not find
an excel function to do this. I appreciate any help submitted. Thank
you.

tom



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Converting hex to ascii

Hello,

To be able to work with hex numbers you have to install the Add-In "Analysis
Toolpack" first (Tools Menu, Add-Ins and check the Analysis Toolpack
checkbox).
You may need the Office Installation CD to do this.
When this is done you find a new function category (Insert Function) with
the name "Engineering". In this function category you fine several functions
like Hex2Dec.

In VB it seems to be more complicated.
The sub:

Dim Dec1 As Long

Dec1 = "&hF"

End Sub

will return the value 15 for Dec1, but if you use a variable input like in
this sub:

Dim Hex1 As String
Dim Dec1 As Long

Sub HexTest()

Hex1 = "F"
Dec1 = "&h(Hex1)"

End Sub

Then I get a "type mismatch" error.

So if someone can help me how to avoid this problem I wil be very grateful.

Thanks beforehand,

Gerrit


In EXCEL you have to install the
"Tom" schreef in bericht
om...
How do I convert a hex byte into an ascii character? I'll take an
excel formula or VB code. Either way would be fine. I could not find
an excel function to do this. I appreciate any help submitted. Thank
you.

tom



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Converting hex to ascii

Two possibilities:

Sub HexTest()
Dim hex1 As String
Dim dec1 As Integer
hex1 = "F"
dec1 = "&h" & hex1
MsgBox dec1
hex1 = "ff"
MsgBox hx2dc(hex1)
End Sub

Function hx2dc(s$) As Long
hx2dc = "&h" & s$
End Function


Gerrit van Stempvoort wrote:
Hello,

To be able to work with hex numbers you have to install the Add-In "Analysis
Toolpack" first (Tools Menu, Add-Ins and check the Analysis Toolpack
checkbox).
You may need the Office Installation CD to do this.
When this is done you find a new function category (Insert Function) with
the name "Engineering". In this function category you fine several functions
like Hex2Dec.

In VB it seems to be more complicated.
The sub:

Dim Dec1 As Long

Dec1 = "&hF"

End Sub

will return the value 15 for Dec1, but if you use a variable input like in
this sub:

Dim Hex1 As String
Dim Dec1 As Long

Sub HexTest()

Hex1 = "F"
Dec1 = "&h(Hex1)"

End Sub

Then I get a "type mismatch" error.

So if someone can help me how to avoid this problem I wil be very grateful.

Thanks beforehand,

Gerrit


In EXCEL you have to install the
"Tom" schreef in bericht
om...

How do I convert a hex byte into an ascii character? I'll take an
excel formula or VB code. Either way would be fine. I could not find
an excel function to do this. I appreciate any help submitted. Thank
you.

tom





  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 8
Default Converting hex to ascii

Thanks for your help Rob. I guess I had an older version of VB help
because I could not find any leads to the chr() function.

tom

"Rob van Gelder" wrote in message ...
It's confusing to say "hex byte" because that's mixing presentation with
storage. A Byte is a Byte and can be presented as decimal, hexadecimal,
binary, etc...

So, by Hex Byte I assume you actually mean hex string.

The first is Byte to Ascii, the secon is HexString to Ascii.

Sub test()
Dim byt As Byte, str As String

byt = &H41 'A
Debug.Print Chr(byt)

str = "41"
Debug.Print Chr("&H" & str)
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Tom" wrote in message
om...
How do I convert a hex byte into an ascii character? I'll take an
excel formula or VB code. Either way would be fine. I could not find
an excel function to do this. I appreciate any help submitted. Thank
you.

tom

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
Converting ASCII Into Excel, any Ideas? Cantankerious Excel Discussion (Misc queries) 3 September 27th 06 07:42 PM
converting ascii csv to .txt for financial data fztommy Excel Discussion (Misc queries) 1 February 2nd 06 06:43 AM
email submission tool for converting xls to pdf or xls to plain text ascii Don Saklad Excel Programming 0 February 29th 04 02:38 PM
Ascii Syrus the Virus[_11_] Excel Programming 4 February 3rd 04 02:59 PM
ASCII value Terence Excel Programming 2 October 2nd 03 03:41 AM


All times are GMT +1. The time now is 12:49 PM.

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

About Us

"It's about Microsoft Excel"