
Apr 30th, 2021, 12:00 AM
#1
Thread Starter
Taking a Break
vb6 Convert a value beyond the long range to a hexadecimal number?
I want to convert a decimal number to a hexadecimal number program, to convert a value beyond the long range to a hexadecimal number, is there a way, 20200430110900, how to become 125F477608B4
Code:
Public Function DEC_to_HEX(Dec As Currency) As String
Dim a As String
DEC_to_HEX = ""
Do While Dec > 0
a = CStr(Dec  16 * Int(Dec / 16))
Select Case a
Case "10": a = "A"
Case "11": a = "B"
Case "12": a = "C"
Case "13": a = "D"
Case "14": a = "E"
Case "15": a = "F"
End Select
DEC_to_HEX = a & DEC_to_HEX
Dec = Int(Dec / 16)
Loop
End Function
Code:
Function LongToHexStr(LongV As String) As String
Dim js As Object
'dim Js As ScriptControl :Set js = New ScriptControl
Set js = CreateObject("ScriptControl")
js.Language = "javascript"
js.AddCode "var num = " & LongV & ";"
LongToHexStr = js.Eval("num.toString(16).toUpperCase()")
Set js = Nothing
End Function
Function LongToHexStr(LongV As String) As String
Dim js As Object: Set js = CreateObject("ScriptControl"): js.Language = "javascript"
LongToHexStr = js.Eval("var num=" & LongV & ";num.toString(16).toUpperCase()")
End Function
Last edited by xiaoyao; Apr 30th, 2021 at 01:29 AM.

Apr 30th, 2021, 04:20 AM
#2
Re: vb6 Convert a value beyond the long range to a hexadecimal number?
Code:
snwprintf1 StrPtr(sBuf), Len(sBuf), StrPtr("0x%llx"), ByVal CCur(123456789@)
' // Output: 0x11f71fb0450

Apr 30th, 2021, 04:31 AM
#3
Re: vb6 Convert a value beyond the long range to a hexadecimal number?
How to use snwprintf1 can be found in the AddIn thread by The Trick:
https://www.vbforums.com/showthread....=1#post5509861
This seems to work too:
Code:
Private Sub Form_Load()
Dim c As Currency
c = 20200430110900#
Debug.Print CurToHex(c)
End Sub
Private Function CurToHex(ByVal cValue As Currency) As String
Dim c As Currency, r As Long
Do While cValue > 0
c = cValue / 16
r = 16 * (c  Int(c))
CurToHex = Hex$(r) & CurToHex
cValue = Int(c)
Loop
End Function
Based on the explanation on this site:
https://www.rapidtables.com/convert/...altohex.html
Last edited by Arnoutdv; Apr 30th, 2021 at 04:57 AM.

Apr 30th, 2021, 07:58 AM
#4
Re: vb6 Convert a value beyond the long range to a hexadecimal number?
once you start working with 64 bit numbers its nice to have a complete lib
https://github.com/dzzie/libs/tree/master/vb6_utypes
Code:
Private Sub Form_Load()
Dim u As New ULong64
u.fromString "20200430110900", mUnsigned
Debug.Print u.toString() ' 125F`477608B4
End Sub
Code:
'ULong64
'Variables
Dim hLib As Long
Public use0x As Boolean
Public useTick As Boolean
Public padLeft As Boolean
Public rawValue As Currency 'this is the default property of the class
Public mode As modes
'Properties
Property lo() As Long
Property hi() As Long
Property isNegBitSet() As Boolean
Property is32BitSafe() As Boolean
Property MAX_UNSIGNED64() As String
Property MIN_SIGNED64() As String
Property MAX_SIGNED64() As String
Property Value()
'Methods
Function rol32(operand2) As ULong64
Function lessThanEqual(operand2) As Boolean
Function greaterThanEqual(operand2) As Boolean
Function lessThan(operand2) As Boolean
Function greaterThan(operand2) As Boolean
Function lshift(operand2) As ULong64
Function rshift(operand2) As ULong64
Function or_(operand2) As ULong64
Function and_(operand2) As ULong64
Function xor_(operand2) As ULong64
Function modulus(operand2) As ULong64
Function multiply(operand2) As ULong64
Function divide(operand2) As ULong64
Function subtract(operand2) As ULong64
Function add(operand2) As ULong64
Function raw_op(operand2, operation As op) As ULong64
Sub GetLongs(Optional ByRef hi As Long, Optional ByRef lo As Long)
Sub SetLongs(Optional hi As Long, Optional lo As Long)
Function fromString(ByVal s As String, Optional m As modes = mHex) As Boolean
Function toString(Optional m As modes = mHex) As String
Function setVal(v) As ULong64
'Variables hLib use0x useTick padLeft rawValue mode
'Properties lo hi isNegBitSet is32BitSafe MAX_UNSIGNED64 MIN_SIGNED64 MAX_SIGNED64 Value
'Methods rol32 lessThanEqual greaterThanEqual lessThan greaterThan lshift rshift or_ and_ xor_ modulus multiply divide subtract add raw_op GetLongs SetLongs fromString toString setVal

Apr 30th, 2021, 07:59 AM
#5
Re: vb6 Convert a value beyond the long range to a hexadecimal number?
Except that a Currency is not "decimal" but instead a signed binary integer scaled by 10000. Why do people imagine binary values to be "decimal?" Or is this just more language imprecision?
Even a VT_DECIMAL is not "decimal" but more like a Currency which carries a power of 10 ("digits") scaling factor.
There is no "decimal" type at all.

Apr 30th, 2021, 12:21 PM
#6
Re: vb6 Convert a value beyond the long range to a hexadecimal number?
dilettante, your post is useless. who cares about semantics, in the end its about the practical use of the type.
otherwise everything is just binary, 0 and 1.
also you can use the type to be octal if you wish. so you decide what the type is.
and talking about binary. you can convert a decimal (09) into binary (01) and after that convert it into hexadecimal (000F)

Apr 30th, 2021, 12:32 PM
#7
Re: vb6 Convert a value beyond the long range to a hexadecimal number?
I think Dilettante means the correct terms should be a representation in Base 10 or in Base 16.
But like many others, I'm also not a native English speaker, so we make to best of it to understand each other.

Apr 30th, 2021, 12:58 PM
#8
Re: vb6 Convert a value beyond the long range to a hexadecimal number?
I get that Arnoutdv, and if you are discussing technicalities, he's correct about that.
but he's also wrong, as in the end its binary and if we are going even deeper its about circuits, transistors and electronic signals, and if we go even deeper, its atoms and elementary particles and mass, charge and 'spin and if we go deeper well... now its just theory.
for me its about context, and nobody asked for a lesson of what is a type, but how to convert decimal (base 10) into hex (base 16) for values above what long type can hold.

Apr 30th, 2021, 01:30 PM
#9
Re: vb6 Convert a value beyond the long range to a hexadecimal number?
It isn't semantics, it's about understanding computers.
This sort of "I think it is decimal, it's my party and I'll cry if I want to" is why people go so wrong. For example getting wrapped around the axle by the limitations of floatingpoint data types and operations.
There are numeric data types and operations that really are decimal, we just don't have them in most Windows programming languages.

May 5th, 2021, 08:38 PM
#10
Thread Starter
Taking a Break
Re: vb6 Convert a value beyond the long range to a hexadecimal number?
Originally Posted by dz32
once you start working with 64 bit numbers its nice to have a complete lib
https://github.com/dzzie/libs/tree/master/vb6_utypes
Code:
Private Sub Form_Load()
Dim u As New ULong64
u.fromString "20200430110900", mUnsigned
Debug.Print u.toString() ' 125F`477608B4
End Sub
Code:
'ULong64
'Variables
Dim hLib As Long
Public use0x As Boolean
Public useTick As Boolean
Public padLeft As Boolean
Public rawValue As Currency 'this is the default property of the class
Public mode As modes
'Properties
Property lo() As Long
Property hi() As Long
Property isNegBitSet() As Boolean
Property is32BitSafe() As Boolean
Property MAX_UNSIGNED64() As String
Property MIN_SIGNED64() As String
Property MAX_SIGNED64() As String
Property Value()
'Methods
Function rol32(operand2) As ULong64
Function lessThanEqual(operand2) As Boolean
Function greaterThanEqual(operand2) As Boolean
Function lessThan(operand2) As Boolean
Function greaterThan(operand2) As Boolean
Function lshift(operand2) As ULong64
Function rshift(operand2) As ULong64
Function or_(operand2) As ULong64
Function and_(operand2) As ULong64
Function xor_(operand2) As ULong64
Function modulus(operand2) As ULong64
Function multiply(operand2) As ULong64
Function divide(operand2) As ULong64
Function subtract(operand2) As ULong64
Function add(operand2) As ULong64
Function raw_op(operand2, operation As op) As ULong64
Sub GetLongs(Optional ByRef hi As Long, Optional ByRef lo As Long)
Sub SetLongs(Optional hi As Long, Optional lo As Long)
Function fromString(ByVal s As String, Optional m As modes = mHex) As Boolean
Function toString(Optional m As modes = mHex) As String
Function setVal(v) As ULong64
'Variables hLib use0x useTick padLeft rawValue mode
'Properties lo hi isNegBitSet is32BitSafe MAX_UNSIGNED64 MIN_SIGNED64 MAX_SIGNED64 Value
'Methods rol32 lessThanEqual greaterThanEqual lessThan greaterThan lshift rshift or_ and_ xor_ modulus multiply divide subtract add raw_op GetLongs SetLongs fromString toString setVal
Very good, I will test it when I have time, thank you for your warm help
Learn a lot in this forum.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
