Andrew P. presented the following explanation :
> GOT IT!!!!!
>
> Solution:
> Work on the HEX string 2 digits at a time, and take the result of Chr(), not
> the string containing "Chr(xx)". And its even working in the real world, not
> just a HEX editor. Happy days!
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> For i = 1 To Len(hexstring) Step 2
> Dim temp As String
> temp = WorksheetFunction.Hex2Dec(Mid(hexstring, i, 2))
> outputstring = outputstring & Chr(temp)
> Next i
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> "Andrew P." wrote:
>
>> Hello All
>>
>> I'm using "modCOMM - Written by: David M. Hitchner" to send data out of the
>> serial port. I need to send HEX strings (eg 0E0E00000505000C20450164A5A5 )
>> to external devices. Each part of the string is 2 HEX characters. If I send
>> a HEX string directly to it, I get incorrect data at the other end.
>>
>> By using 2 HEX programs and a null cable, I can pass the strings correctly
>> to the equipment, and also monitor what Excel is sending out of the serial
>> port.
>>
>> If I send this -> I get this on the HEX comms program
>>
>> 0E0E00000505000C20450164A5A5 ->
>> 3045304530303030303530353030304332303435303136344135413500
>>
>> 0 -> 30
>> 1 -> 31
>> A -> 41
>> a ->61
>> 0E -> 3045
>> Chr(1) & Chr(255) -> 01FF
>>
>> So, I can see that there is a way to get the correct data out, but I don't
>> want to have to encode each and every pair of HEX digits into a "chr()".
>> Whats the intelligent way of getting a string?
>>
>> Thanks a lot!!
>> Andrew
Curious...
I don't see how the code you posted here returns the result you say it
gave you. It appears that your Chr() function returns a different set
of values than VB's Chr() function, because using this example returns
gobbly-gook characters. I suspect you're using a custom algorythm to
convert to Chr().
Is the Hex2Dec() you refer to here part of the Analysis Toolpak addin?
Or is it custom? <FYI>The result of passing each iteration of your
For...Next loop on the original 28 character HexString to Hex2Dec()
returns the following 14 values:
"14,14,0,0,5,5,0,12,32,69,1,100,165,165"
How does that become what you post here? For example, Chr(14) (result
of passing "0E") returns "", not 3045. Not only that, your reported
result has 2 extra characters (Len()=58, not 56).
Clearly, there's some missing info here. I suspect your "modComm"
program uses its own custom functions to process the original HexString
to get the result you claim it gives you. Not sure why you need to use
2 Hex progs to achieve the same result. Why not just get the same
function the modComm prog uses and use it with VBA by way of a lookup
function?
regards,
--
Garry
Free usenet access at
http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc