XLEAccessGuru
XLEGuru
- Local time
- Today, 03:41
- Joined
- Nov 17, 2006
- Messages
- 65
Anyone know why "99.5 Mod 10" would return 0? I'm using Access VBA 2007 and Mod doesn't seem to be working right.
Data types being used are currency although I did try changing the variable data type to see if it would make a difference.
Try the code below like this - GetTransactionAmount(101.5) - and see what you get. It keeps returning the amount passed to it because the Mod operator doesn't seem to be returning correct values.
Any ideas?
Data types being used are currency although I did try changing the variable data type to see if it would make a difference.
Try the code below like this - GetTransactionAmount(101.5) - and see what you get. It keeps returning the amount passed to it because the Mod operator doesn't seem to be returning correct values.
Any ideas?
Code:
Public Function GetTransactionAmount(TransAmt As Currency) As Currency
'this function is used to extract the actual amount withdrawn
'from an ATM machine even when a surcharge was applied to the whole transaction amount.
'ASSUMPTIONS:
' -ATM surcharges will never exceed $9.00 in the dataset the function is being used in
' -ATM withdrawal amounts will always be divisible by 10
' -ATM surcharges are only charged in increments of $0.25 (eg. an ATM will not charge a fee of $2.99)
' -All ATM machines only dispense whole dollar amounts divisible by 10.
Dim cSurchgTestAmt(100) As Double
Dim cNewAmt As Double
Dim i As Integer, x As Double, y As Double
x = 2.25
cSurchgTestAmt(i) = 4.25
For i = 0 To 100
cSurchgTestAmt(i) = x - 0.25
cNewAmt = TransAmt - cSurchgTestAmt(i)
If cNewAmt Mod 10 = 0 Then
GetTransactionAmount = TransAmt - cSurchgTestAmt(i)
Exit Function
End If
x = cSurchgTestAmt(i)
Next i
MsgBox "The 'GetTransactionAmount' function could not extract a value.", vbCritical, "Currency Extraction Error"
End Function