Search
Search

# How Convert the number from hexadecimal to decimal in Crystal XI?

Hi:

I am working on the report with a Invoice ID which is stored in the DB2 database as Varchar(16), the data look like '000000000000000000000000000130D', but the Crystal report need to convert this hexadecimal invoice ID to decimal number, it should look like '4877', actually, most science calculators would have this conversion function. But I canu2019t find this function in Crystal report nor DB2.

I have done some research, the logic hex (16) to decimal is :

since A=10, B=11,C=12,D=13,E=14,F=15

130D= 1X163+3X1620X16^113X16^0=4877

Can some one tell me how to convert the hex number to decimal number in Crystal report?

Thanks!

##### Former Memberreplied

Hi Adelson , I have test my code as below:

***********************************************

Function HEXtodec ( Hex As String) As Number

Dim i As Number

Dim B As Number

Hex = UCase(Hex)

For i = 1 To Len(Hex)

Select Case Mid(Hex, Len(Hex) - i + 1, 1)

Case "0"

B = B + 16 ^ (i - 1) * 0

Case "1"

B = B + 16 ^ (i - 1) * 1

Case "2"

B = B + 16 ^ (i - 1) * 2

Case "3"

B = B + 16 ^ (i - 1) * 3

Case "4"

B = B + 16 ^ (i - 1) * 4

Case "5"

B = B + 16 ^ (i - 1) * 5

Case "6"

B = B + 16 ^ (i - 1) * 6

Case "7"

B = B + 16 ^ (i - 1) * 7

Case "8"

B = B + 16 ^ (i - 1) * 8

Case "9"

B = B + 16 ^ (i - 1) * 9

Case "A"

B = B + 16 ^ (i - 1) * 10

Case "B"

B = B + 16 ^ (i - 1) * 11

Case "C"

B = B + 16 ^ (i - 1) * 12

Case "D"

B = B + 16 ^ (i - 1) * 13

Case "E"

B = B + 16 ^ (i - 1) * 14

Case "F"

B = B + 16 ^ (i - 1) * 15

End Select

Next i

HEXTODEC = B

End Function

*****************************************

but there are something you have to be caution:

1.be sure you choose the VB syntax when you create a New Function in your report.

2.when you use the Function,you can be test such as: hextodec ('01f2')

if you have any problem, contact me free yourself !

Edited by: Hugo Huang on Oct 12, 2008 11:39 AM

0 View this answer in context
View more on this topic or