Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format question 1

Status
Not open for further replies.

Chummly66

MIS
Feb 19, 2005
106
US
I have this code which converts a 11 digit number into an 8 digit hex number.

left3 = Left([txtESNdec], 3)
right8 = Right([txtESNdec], 8)
hexleft = Hex(left3)
hexright = Hex(right8)
hex_number = hexleft & Format(hexright, "000000")

Me.[txtESNHEX] = hex_number
Me.txtDateCode.SetFocus

Everything works perfectly, except in the one instance where the "hexright" value comes out with a zero for its first number.

For example, if hexleft = 1E and hexright = 20ED1A, then I get the result of 1E20ED1A and thats exactly right. But in the one instance where the hexright value starts with a zero, I get: hexleft = 1E, hexright = 02ED1A, then I get a result of 1E2ED1A, even with the "format(hexright, "000000") line.

I used this same code before for my decimal conversions and it worked for that, so I am not sure why this one isn't working.

thanks for the help in advance guys!
Richard
 
And this ?
hex_number = hexleft & Right("000000" & hexright, 6)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Wow, PH to the rescue one more time.

Thanks!! that worked perfectly.
Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top