Hi guys, I'm having a problem when trying to compare two floating values, and I have no idea what happens here, I hope someone can help me out with this.
What I need is to compare a value stored in a table (set up as a double on it) with a operation done, and return true or false if it is the same. What happens is that when I do so, even the value being showed as equal in the debugger, it still sends it wrong to me.
I don't understand what is wrong, everything working nicely but even the values being the same, still randomly shows "Wrong!" in a lot of cases. In the debugger shows something like this:
If any of you could help me with this it would be higjly appreciated. Thanks in advance.
What I need is to compare a value stored in a table (set up as a double on it) with a operation done, and return true or false if it is the same. What happens is that when I do so, even the value being showed as equal in the debugger, it still sends it wrong to me.
Code:
'//Setting variables.
Dim rsStock As Recordset
Dim bRecord As Double
Dim bIn As Double
Dim bOut As Double
Dim bCurrent As Double
'//Setting the recordset.
Set rsStock = CurrentDb.OpenRecordset("SELECT tblStock.* FROM tblStock ORDER BY [tblStock]![Date]", dbOpenDynaset)
rsStock.MoveFirst
bCurent = 0
'//Loop through all records to check if the balance is correct at all records.
While Not rsStock.EOF = True
'//Capturing value from record.
bRecord = rsStock.Fields("Balance")
'//Making operation to get correct value.
If rsStock.Fields("In") > 0 Then
bIn = rsMStock.Fields("In")
bCurrent = Round(bCurrent + bIn, 2)
End If
If rsStock.Fields("Out") > 0 Then
bOut = rsMStock.Fields("Out")
bCurrent = Round(bCurrent - bOut, 2)
End If
'//Checking if the value in table is equal to the operation made in the loop.
If bCurrent <> bRecord Then
Debug.Print "(" & rsMStock.Fields("IDStock") & ") [" & bCurrent & "/" & bRecord & "] [Wrong!]"
Else
Debug.Print "(" & rsMStock.Fields("IDStock") & ") [" & bCurrent & "/" & bRecord & "] [Correct!]"
End If
rsStock.MoveNext
Wend
rsStock.Close
Set rsStock = Nothing
I don't understand what is wrong, everything working nicely but even the values being the same, still randomly shows "Wrong!" in a lot of cases. In the debugger shows something like this:
Code:
(159) [9,47/9,47] [Correct!]
(261) [12,1/12,1] [Wrong!]
(407) [89,6/89,6] [Correct!]
(610) [82,37/82,37] [Wrong!]
(650) [79,29/79,29] [Wrong!]
(669) [76,17/76,17] [Wrong!]
(1525) [73,5/70,82] [Wrong!]
(1521) [70,82/73,49] [Wrong!]
(1527) [68,96/68,96] [Correct!]
If any of you could help me with this it would be higjly appreciated. Thanks in advance.