Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Dim bytes(0 To 7)
Dim c As Long
dHex 3.141592654, bytes
For c = 0 To 7
Print bytes(c)
Next
End Sub
'in a .bas
Option Explicit
Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Public Function dHex(dblVal As Double, byteArray) As String
'double variable ONLY to hex
Dim c As Long, dHex2 As String
Dim dVal As Double, sTemp As String
Dim b(0 To 8) As Byte
dVal = CDbl(dblVal)
CopyMemory b(0), dVal, 8
For c = 0 To 7
byteArray(c) = b(c)
Next
'Debug.Print b(0), b(1), b(2), b(3), b(4), b(5), b(6), b(7)
For c = 0 To 7
sTemp = Hex(b(c))
sTemp = String(2 - Len(sTemp), "0") & sTemp
dHex2 = dHex2 & sTemp
Next
dHex = dHex2
For c = 1 To 8
If Mid(dHex2, c, 1) = "0" Then
dHex = Mid(dHex, 2)
Else
Exit For
End If
Next
If dHex = "" Then dHex = "0"
End Function