Visual Basic 6 function "two_longs_to_variant"

Go back

Below you'll find the source for the Visual Basic 6 function two_longs_to_variant.

Attribute VB_Name = "modTwoLongsToVariant"
' This function is downloaded from:
' http://www.stefanthoolen.nl/archive/vb6-functions/
' 
' You may freely distribute this file but please leave all comments, including this one, in it.
' 
' @Author Stefan Thoolen <mail@stefanthoolen.nl>

Option Explicit

''
' Combines two Long values to one variant (for QuadWORDs)
' @param    long     long1      The first value
' @param    long     long2      The second value
' @return   Variant             Both values combined
' @author   Steven Don <www.shdon.com>
Public Function two_longs_to_variant(long1 As Long, long2 As Long) As Double
    Dim ret As Double
    Dim bit31 As Double, bit63 As Double
    
    bit31 = &H8000
    bit31 = bit31 * &H10000
    bit63 = bit31 * bit31
    bit63 = bit63 * 2
    
    'Move long2 into upper 32 bits, excluding sign bit
    ret = (long2 And &H7FFFFFFF)
    ret = ret * &H10000
    ret = ret * &H10000
    
    'Move long1 into lower 31 bits
    ret = ret + (long1 And &H7FFFFFFF)
    
    'Take care of sign bits
    If (long1 < 0) Then ret = ret + bit31
    If (long2 < 0) Then ret = ret + bit63
    
    two_longs_to_variant = ret
End Function