Why does this code generate false data

H

Henro

I have the following code that calculates totals of short times.
To be more precise: it adds all the hours somebody worked more than
he/she should have and totals them.
Now this funny thing happens: as soon as somebody works less than
he/she should one EXTRA hour gets added.

Example: Edwin works three days, the third day he works one hour too
much, (not probable ;p), that goes fine. But as soon as he works less
than he should (very probable ;p) one hour extra gets subtracted. So
let's say he worked 8:30 instead of 9:00, he should have a total of
minus half an hour. But he gets a total of -1:30. It doesn't matter
how often he works too much or to less. As soon as he works too less
for one day one hour too much gets substracted.
So, i.e. regardless if he works ten days ten hours too little, as soon
as he has one day of negative total there is one negative hour too
much.

------------------------CODE-----------------------------

Function TotME(varFieldName As Variant) As String
On Error GoTo ProcError

Dim db As DAO.Database, rs As DAO.Recordset
Dim totaaluren As Long, totaalminuten As Long
Dim uren As Long, minuten As Long
Dim Interval As Variant, j As Integer


Set db = DBEngine.Workspaces(0).Databases(0)
Set rs = db.OpenRecordset("Uren tbv verzamelengineer")

Interval = #12:00:00 AM#
rs.MoveFirst



While Not rs.EOF
If Not IsNull(rs(varFieldName)) Then
Interval = Interval + rs(varFieldName)
End If
rs.MoveNext
Wend



totaaluren = Int(CSng(Interval * 24))
totaalminuten = Int(CSng(Interval * 1440))
uren = totaaluren Mod 24
minuten = totaalminuten Mod 60

TotME = totaaluren & ":" & minuten
ExitProc:
On Error Resume Next
rs.Close
db.Close
Exit Function

ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
, "Uren kunnen niet worden getotaliseerd..."
Resume ExitProc
End Function

-------------------------CODE----------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Another Code Wizard Question 7
Calculating Time 5
Problem w/Date time function 2
Function & Querys 1
Function and Query 4
Unresolved Issue about totaling Downtime Hours 1
Date, Time Calculations 1
Time Function 3

Top