ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   working with Hex numbers.... A few gotchas I need help with... (https://www.excelbanter.com/excel-programming/424531-working-hex-numbers-few-gotchas-i-need-help.html)

Phillip[_7_]

working with Hex numbers.... A few gotchas I need help with...
 
I am working with Hex numbers in a worksheet
I have the numbers that are sent to me in the following formats:
0011E3637679:
0011E3CC7E0D:
0015CEE79A4B:
00189B1B8287:
0011E3A60085:

Each number for the MOST part, I have it working fine.

The problem occurs when the address is ONLY numbers (still a valid HEX)
Something like
001892080747:

and also an issue comes when I come across something that LOOKS like
SCIENTIFIC notation like:
0018920807E7:


Here is a sample of my code that I use:
'lngin is defined as column "b" & row() in a for next loop
lngin = teststr1
t1 = Right(lngin, 10) 'all of the hex do start with "00", so this
gives me the plain HEX num,
'with the 2 leading "00" removed as well as the ":" removed
t2 = Application.Hex2Dec(t1) + 1
t3 = Application.Dec2Hex(t2)
RtnStr = "'00" & Application.Text(t3, 999999999999#)

'Now to write the new number to a different column (defined as Tocol3 &
then the row - icount)
celname = tocol3 & Str(icount)
curcel2 = Application.Substitute(celname, " ", "")
Range(curcel2).Value = RtnStr

end of snipett

Sample:
001095180651 will return 00999999999999
0020407080E2 will return 00999999999999


Any suggestions?

Thanks
Phil





Per Jessen

working with Hex numbers.... A few gotchas I need help with...
 
Hi

Try this:

RtnStr = "'00" & t3

BTW: You should always tell us the desired result, for reference.

Regards,
Per

"Phillip" skrev i meddelelsen
...
I am working with Hex numbers in a worksheet
I have the numbers that are sent to me in the following formats:
0011E3637679:
0011E3CC7E0D:
0015CEE79A4B:
00189B1B8287:
0011E3A60085:

Each number for the MOST part, I have it working fine.

The problem occurs when the address is ONLY numbers (still a valid HEX)
Something like
001892080747:

and also an issue comes when I come across something that LOOKS like
SCIENTIFIC notation like:
0018920807E7:


Here is a sample of my code that I use:
'lngin is defined as column "b" & row() in a for next loop
lngin = teststr1
t1 = Right(lngin, 10) 'all of the hex do start with "00", so this
gives me the plain HEX num,
'with the 2 leading "00" removed as well as the ":" removed
t2 = Application.Hex2Dec(t1) + 1
t3 = Application.Dec2Hex(t2)
RtnStr = "'00" & Application.Text(t3, 999999999999#)

'Now to write the new number to a different column (defined as Tocol3 &
then the row - icount)
celname = tocol3 & Str(icount)
curcel2 = Application.Substitute(celname, " ", "")
Range(curcel2).Value = RtnStr

end of snipett

Sample:
001095180651 will return 00999999999999
0020407080E2 will return 00999999999999


Any suggestions?

Thanks
Phil






Phillip[_7_]

working with Hex numbers.... A few gotchas I need help with...
 

RtnStr = "'00" & t3

So simple! I guess the "Keep it simple stupid" rule applies! It makes sense
becuz t3 is dim as string! That was a carry over from some earlier trials...
It works!


BTW: You should always tell us the desired result, for reference.

I know this.... I should have

Thanks




All times are GMT +1. The time now is 11:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com