HughLerwill
Programmer
I'm trying to simulate logical AND and OR on Currency variables. So far I have the code below but it is not quite working e.g. CurrencyAND(1,3) is returning 0.9488 instead of 1; CurrencyOR(1,3) is returning 3.0512 rather than 3.
Could be I have a couple of the Hi/Los reversed or is it more complicated?
Could be I have a couple of the Hi/Los reversed or is it more complicated?
Code:
'ref [URL unfurl="true"]http://support.microsoft.com/kb/189862[/URL]
'jan 2013
Private Type MungeCurr
Value As Currency
End Type
Private Type Munge2Long
LoValue As Long
HiValue As Long
End Type
Public Function CurrencyAND(C1 As Currency, C2 As Currency) As Currency
Dim Lo1&, Hi1&, Lo2&, Hi2&
CurrencyToTwoLongs C1, Lo1, Hi1
CurrencyToTwoLongs C2, Lo2, Hi2
Dim RetLo&, RetHi&
RetLo& = Lo1 And Lo2
RetHi& = Hi1 And Hi2
CurrencyAND = TwoLongsToCurrency(RetLo&, RetHi&)
End Function
Public Function CurrencyOR(C1 As Currency, C2 As Currency) As Currency
Dim Lo1&, Hi1&, Lo2&, Hi2&
CurrencyToTwoLongs C1, Lo1, Hi1
CurrencyToTwoLongs C2, Lo2, Hi2
Dim RetLo&, RetHi&
RetLo& = Lo1 Or Lo2
RetHi& = Hi1 Or Hi2
CurrencyOR = TwoLongsToCurrency(RetLo&, RetHi&)
End Function
Private Function TwoLongsToCurrency(Long1, Long2) As Currency
'ref [URL unfurl="true"]http://support.microsoft.com/kb/189862[/URL]
Dim C As MungeCurr, L As Munge2Long
L.HiValue = Long1
L.LoValue = Long2
LSet C = L
TwoLongsToCurrency = C.Value
End Function
Private Sub CurrencyToTwoLongs(MyC As Currency, Long1, Long2)
'ref [URL unfurl="true"]http://support.microsoft.com/kb/189862[/URL]
Dim C As MungeCurr, L As Munge2Long
C.Value = MyC
LSet L = C
Long1 = L.HiValue
Long2 = L.LoValue
End Sub