Concatenation Revisited...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I took a look at the stringbuilder solutions discussed earlier today... and I have a question that is also tied to a result that is currently having me scratch my head. It looks like this:

Dim hexString1 as String
Dim hexString2 as String
Dim hexResult as String

hexString1 = Hex$(decValue1)
hexString2 = Hex$(decValue2)
hexResult = hexString1 & hexString2

main.output.additem(hexResult)

A couple things to note: hexString1 and hexString2 will always be used to represent one byte of data each. So the range of hexResult would be 0000h to FFFFh.

The code above seems to work in all instances, except in instances where the upper nibble of hexString2 is equal to Zero (ie: XX0Xh). When the value shows up as XX0Xh, the result appears as XX00h.

Is this normal? Any suggestions?
 
Jvangel,
The following gives what I believe you are asking for:

Dim decValue1 As Byte = 10
Dim decValue2 As Byte = 20
Dim hexResult As String = decValue1.ToString("X2") &
decValue2.ToString("X2")

The "problem" with Hex$ is it will only return a single hex digit for 0 to
15, where as ToString("X2") says you want Hex with 2 digits no matter what.

Hope this helps
Jay


jvangel said:
I took a look at the stringbuilder solutions discussed earlier today...
and I have a question that is also tied to a result that is currently having
me scratch my head. It looks like this:
Dim hexString1 as String
Dim hexString2 as String
Dim hexResult as String

hexString1 = Hex$(decValue1)
hexString2 = Hex$(decValue2)
hexResult = hexString1 & hexString2

main.output.additem(hexResult)

A couple things to note: hexString1 and hexString2 will always be used to
represent one byte of data each. So the range of hexResult would be 0000h
to FFFFh.
The code above seems to work in all instances, except in instances where
the upper nibble of hexString2 is equal to Zero (ie: XX0Xh). When the value
shows up as XX0Xh, the result appears as XX00h.
 
Back
Top