I am fairly new to VB6 and I would like to convert a parameter from Double to Hex and back to Long for Chinese Unicode.

The issue here is for input values from 1-127, the output is the same. For values beyond 127, the output is 63. The parameter is 4 bytes long. Here's a snippet of the 2 conversion functions I have used so far:

DoubleToHex:

Code:

Code:
Public Function ConvDoubleToHexString(dVal As Double, ByVal nByteCount As Integer) As String

Dim sHex As String
Dim sTmp As String
Dim n As Integer
Dim m As Long
Dim sRet As String
Dim nByteCountMerk As Integer

m=1
sHex = Hex(dVal)

nByteCountMerk = nByteCount
If nByteCount < Len(sHex) / 2 Then nByteCount = Len(sHex) / 2
If nByteCount < 1 Then nByteCount = 1

sHex = String(nByteCount * 2 - Len(sHex), "0") & sHex 
For n = 0 To nByteCount - 1

sTmp = ChrW(Val("&H" & Mid(sHex, m, 2)))
m = m + 2
sRet = sRet & sTmp
next n

If Not bLH Then
ConvDoubleToHexString = Right(sRet, nByteCountMerk)
Else
For n = Len(sRet) To 1 Step -1
  sLH = sLH & Mid(sRet, n, 1)
Next n
ConvDoubleToHexString = Left(sLH, nByteCountMerk)
End If

End Function


HexToLong:


Code:
Public Function ConvHexStringToLong(sHex As String) As Long

Dim sHex As String
Dim sTmp As String
Dim n As Integer
Dim m As Long
Dim sRet As String
Dim nByteCountMerk As Integer

If sHex = "" Then
ConvHexStringToLongAbs = knolong
Exit Function
End If

For i = 1 To Len(sHex)
If l >= 8388608 Then
  ConvHexStringToLongAbs = knolong
  Exit Function
End If

l = l * 256 * 2
l = l + Asc(Mid(sHex, i, 1))
Next

ConvHexStringToLong = l

End Function