I use this to get a value as signed long,
Its ok, but this has a correction. The previous formula was:
p = CDec(Int(A))
What's wrong?
If we have a Currency type A say 100 the Signed return 1000000...Why?
Because p as VBDecimal not store 100 as binary, but the actual binary form of Currency, which is multiplied by 1000 and just pass a "decimal shift" of 4 digits, a division of 1000. So the right formula is the Fix(CDec(A)) which first place the Currency type as is in a Decimal type, and then the Fix() statement just remove the "decimal shif" applying the division.
The MemLong() function is from https://github.com/cristianbuse/VBA-MemoryTools
The signed() function works with type 20 (Long Long) too. So it is the low 4 bytes of a Long Long.
Code:
Public Function Signed(A) As Long
Dim p
p = Fix(CDec(A))
Signed = MemLong(VarPtr(p) + 8)
End Function
p = CDec(Int(A))
What's wrong?
If we have a Currency type A say 100 the Signed return 1000000...Why?
Because p as VBDecimal not store 100 as binary, but the actual binary form of Currency, which is multiplied by 1000 and just pass a "decimal shift" of 4 digits, a division of 1000. So the right formula is the Fix(CDec(A)) which first place the Currency type as is in a Decimal type, and then the Fix() statement just remove the "decimal shif" applying the division.
The MemLong() function is from https://github.com/cristianbuse/VBA-MemoryTools
The signed() function works with type 20 (Long Long) too. So it is the low 4 bytes of a Long Long.