Problem Converting Hex to Decimal
-
Hello, this is Vikash. I am facing a problem related to Conversion of Hex String into Decimal Value. The problem does not occur when the code is run in VB.net 2005. But the same Code when run in VB6.0 gives a negative value. This is the Code in VB.net : dim C as string C = CDec("&H" & "8CF1152C") The Value of C in this case is "2364609836" The same Code in VB6.0 gives C value as "-1930357460" Could anyone tell me why this is happening or how to solve this problem? Any help would be highly appreciated. Thanks In Advance.
-
Hello, this is Vikash. I am facing a problem related to Conversion of Hex String into Decimal Value. The problem does not occur when the code is run in VB.net 2005. But the same Code when run in VB6.0 gives a negative value. This is the Code in VB.net : dim C as string C = CDec("&H" & "8CF1152C") The Value of C in this case is "2364609836" The same Code in VB6.0 gives C value as "-1930357460" Could anyone tell me why this is happening or how to solve this problem? Any help would be highly appreciated. Thanks In Advance.
-
Hello, this is Vikash. I am facing a problem related to Conversion of Hex String into Decimal Value. The problem does not occur when the code is run in VB.net 2005. But the same Code when run in VB6.0 gives a negative value. This is the Code in VB.net : dim C as string C = CDec("&H" & "8CF1152C") The Value of C in this case is "2364609836" The same Code in VB6.0 gives C value as "-1930357460" Could anyone tell me why this is happening or how to solve this problem? Any help would be highly appreciated. Thanks In Advance.
In VB6 an Int is 16 bits and not 32 bits. This is the cause of many, many cross language problems involving VB6.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
Hello, this is Vikash. I am facing a problem related to Conversion of Hex String into Decimal Value. The problem does not occur when the code is run in VB.net 2005. But the same Code when run in VB6.0 gives a negative value. This is the Code in VB.net : dim C as string C = CDec("&H" & "8CF1152C") The Value of C in this case is "2364609836" The same Code in VB6.0 gives C value as "-1930357460" Could anyone tell me why this is happening or how to solve this problem? Any help would be highly appreciated. Thanks In Advance.
Harold has the right answer, the conversion fails because one is signed, and the other isn't. You can do this conversion in VB6 using this code;
'Helperfunctions;
Private Const OFFSET_4 = 4294967296#Function LongToUnsigned(Value As Long) As Double
If Value < 0 Then
LongToUnsigned = Value + OFFSET_4
Else
LongToUnsigned = Value
End If
End Function' Actual conversion;
Dim longNumber As Long
longNumber = &H8CF1152C
unsignedNumber = LongToUnsigned(longNumber)MsgBox (CStr(unsignedNumber))
That should do the trick :)
I are Troll :suss:
-
Hello, this is Vikash. I am facing a problem related to Conversion of Hex String into Decimal Value. The problem does not occur when the code is run in VB.net 2005. But the same Code when run in VB6.0 gives a negative value. This is the Code in VB.net : dim C as string C = CDec("&H" & "8CF1152C") The Value of C in this case is "2364609836" The same Code in VB6.0 gives C value as "-1930357460" Could anyone tell me why this is happening or how to solve this problem? Any help would be highly appreciated. Thanks In Advance.
Thanks everyone for the reply. Solution given by Eddy worked. Now I am getting the same output as in VB.net. Thanks once again.