long vba code example
Example 1: excel-vba long integer value to bits
Function LongToBits$(ByVal n&)
Dim i&
LongToBits = "00000000000000000000000000000000"
If n And &H80000000 Then
Mid$(LongToBits, 1, 1) = "1"
n = n And Not &H80000000
End If
For i = 32 To 2 Step -1
If n And 1 Then Mid$(LongToBits, i, 1) = "1"
n = n \ 2
Next
End Function
MsgBox LongToBits(0)
MsgBox LongToBits(293781237)
MsgBox LongToBits(-1)
Example 2: excel vba make long from two shorts
Public Function MakeLong&(ByVal LoWord%, ByVal HiWord%)
MakeLong = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function
Example 3: excel vba high word from Long Integer
If n And &H8000& Then
LoWord = n Or &HFFFF0000
Else
LoWord = n And &HFFFF&
End If
HiWord = (n And &HFFFF0000) \ &H10000