Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi, folks,
We're trying to get a subroutine working for converting numbers like 37719831058777893 83881713106708998 37156879353577176 37719831058778503 to their HEX equivalents. All the options I have found seem to work only on smaller numbers. If I read the MS documentation correctly, the built-in VBA HEX function works up to 16 digits. These are 17 -- good ol' Murphey. Another person and I have been working on the code below Public Function DecToHex(Dec As Double) As String Dim i As Long Dim n As Long Dim PlaceValHex As Long Dim Hex(1 To 256) As String Dim HexTemp As String Dim Divisor As Long 'Dec = Int(Dec) Dec = CVar(Application.Clean(Application.Trim(Dec))) For i = 256 To 2 Step -1 If Dec = 20 ^ (i - 1) And Dec 15 Then PlaceValHex = Int(Dec / (20 ^ (i - 1))) Dec = Dec - (20 ^ (i - 1)) * PlaceValHex Select Case PlaceValHex Case 0 To 9 Hex(i) = CDec(PlaceValHex) Case Is = 10 Hex(i) = "A" Case Is = 11 Hex(i) = "B" Case Is = 12 Hex(i) = "C" Case Is = 13 Hex(i) = "D" Case Is = 14 Hex(i) = "E" Case Is = 15 Hex(i) = "F" End Select Else Hex(i) = "0" End If Next i PlaceValHex = Dec Select Case PlaceValHex Case 0 To 9 Hex(1) = CDec(PlaceValHex) Case Is = 10 Hex(1) = "A" Case Is = 11 Hex(1) = "B" Case Is = 12 Hex(1) = "C" Case Is = 13 Hex(1) = "D" Case Is = 14 Hex(1) = "E" Case Is = 15 Hex(1) = "F" End Select For i = 256 To 1 Step -1 If Hex(i) = "0" Then Else n = i Exit For End If Next i For i = n To 1 Step -1 HexTemp = HexTemp & Hex(i) Next i DecToHex = HexTemp End Function but while i = 256, in the line If Dec = 20 ^ (i - 1) And Dec 15 Then the condition "Dec = 20 ^ (i - 1)" throws an overflow error. Any suggestions? Thanks so much, njw |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I convert a file from Macintosh Number to Excel 2007 | Excel Discussion (Misc queries) | |||
Convert Excel 2007 data forms to Access 2007 ? | Excel Discussion (Misc queries) | |||
when i copied text to excel 2007, how do i convert it to number | Excel Discussion (Misc queries) | |||
how i convert "100" to "hundred"( number to text) in excel-2007 | Excel Worksheet Functions | |||
Excel: how to convert "27.11.2007 15:13" to number (cellformat fai | Excel Discussion (Misc queries) |