|
Visual Basic (VB and VBA) |
|
Copyright 1999-2001 Christopher Greaves. All rights reserved. Home Page and email to [email protected] |
| If in doubt, record a macro and inspect the entrails! |
Please read the DISCLAIMER.
Here is an INDEX to all the procedures.
You will probably need one copy of my GLOBAL DECLARATIONS.
Public Function strHexToChar(ByVal strText As String) As String
' Procedure : strHexToChar
' Description: Convert a string of hexadecimal digits to a string of characters.
' Copyright: Chris Greaves Inc.
' Inputs: STRING of characters in range 0-9 and A-F.
' Returns: STRING.
' Assumes: Pairs of valid Hex digits are presented.
' Side Effects: None.
' Tested: By the calls shown below.
'Here is a rather unwieldy way of converting a string of hexadecimal (base 16) digit characters to a character string.
'
'Since this is an internal function (called by other procedures, not directly called by the user) I am allowed to make the assumption that the incoming string of hex digits is a valid string; that is, that it is an even number of characters taken from the set 0-9 and A-F.
'
'Somewhere in between the user call (a Macro) and this procedure must be a procedure that checks that the string is valid.
'
'I have a related function lngHexToLong.
'Might be slightly quicker to loop like:
' For i = 1 To Len(HexString) Step 2
' NewString = NewString & Chr$(Val("&H" & Mid$(HexString, i, 2)))
' Next i
'because you don't have to continually re-allocate the original string.
'Ron Mittelman Rmittelman@ Visto.com
'Procs Dim intChar As Integer
Dim strResult As String
' Pad the LHS with hex zero (if required) to make string an even number of digits.
If Len(strText) Mod 2 <> 0 Then
strText = "0" & strText
End If
' Collect two digits at a time
Dim i As Integer
For i = 1 To Len(strText) Step 2
strResult = strResult & Chr$(Val("&H" & Mid$(strText, i, 2)))
Next i
strHexToChar = strResult
'Sub TESTstrHexToChar()
'MsgBox strHexToChar("414243") ' ABC
'End Sub
End Function
| We all knew nothing when we started … |
|
Home Page and Contact Information Send email to [email protected]. This page was last updated Thursday, November 15, 2001 |