How do I keep the leading zeros of HEX characters?

I am parsing incoming serial HEX strings and can’t figure out how to have the leading zeros of HEX characters 01 through 0F display. I use this bit of code in DataAvailable to display the returned string in EditField0:

for i as Integer = 0 to StrLen - 1
  EditField0.AppendText  Str(Hex(mb.byte(i)))
  ByteNum= ByteNum+1
Next i

Now, for example, the string displays as “54212318584”. The actual HEX is “05 04 02 12 31 85 84” and I need it to display as “05040212318584”. How do I keep the leading zeros of each HEX character?

EditField0.AppendText Str(RIGHT("00"+Hex(mb.byte(i)),2))

You can also use ToHex from the new framework.

i.ToHex( 2 )

Thanks Dave!

Old framework, simpler: Str(Hex(Value), "00")

Are you not able to use the old framework’s “EncodeHex()”?