Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1463

64 bit Integer

$
0
0
There is the odd time that you need a 64 bit integer when interfacing with library files. This is easy to do with C++. You simply create a 64 bit unsigned integer. But VB6 does not offer such as service. The only thing that comes close is a Double Precision number, but there are lots of complications using that. No problem, we will just use 2 long integers (32 bit) to make up a single 64 bit integer. But VB6 only allows us to use 31 bits, as the high order bit is used for negative numbers. Drat! We can however utilize 3 long integers, using 24 bits from the first one, 24 bits from the second, and 16 from the third. The following example demonstrates how the 3 integers can be converted into a single string, as well as how the variable would be incremented. If the variable is to be modified in some other fashion, further logic will be required.

J.A. Coutts
Code:

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

    Dim N%
    Dim bTmp(1 To 8) As Byte
    Dim sTmp As String
    Dim TestNum(2) As Long
'    TestNum(0) = 16777215
'    TestNum(1) = 16777215
    Do Until TestNum(2) > 65535
        CopyMemory bTmp(1), TestNum(0), 3
        CopyMemory bTmp(4), TestNum(1), 3
        CopyMemory bTmp(7), TestNum(2), 2
        Debug.Print TestNum(2), TestNum(1), TestNum(0)
        sTmp = StrReverse(StrConv(bTmp, vbUnicode))
        For N% = 1 To Len(sTmp)
            Debug.Print Right$("0" & Hex$(Asc(Mid$(sTmp, N%, 1))), 2) & " ";
        Next N%
        Debug.Print
        If TestNum(0) < 16777215 Then '256 ^ 3 - 1
            TestNum(0) = TestNum(0) + 1
        ElseIf TestNum(1) < 16777215 Then
            TestNum(1) = TestNum(1) + 1
            TestNum(0) = 0
        ElseIf TestNum(2) < 65535 Then '256 ^ 2 - 1
            TestNum(2) = TestNum(2) + 1
            TestNum(1) = 0
        Else
            TestNum(0) = 0
            TestNum(1) = 0
            TestNum(2) = 0
        End If
    Loop


Viewing all articles
Browse latest Browse all 1463

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>