есть коллекция записей состоящая из временных меток
- Код: Выделить всё
ListsDate.Add "start", "21.01.2015 08:30:15", 1
' ListsDate.Add "stop", "21.01.2015 09:50:15", 1
ListsDate.Add "stop", "21.01.2015 10:15:15", 2
ListsDate.Add "start", "21.01.2015 11:55:05", 1
ListsDate.Add "stop", "21.01.2015 13:20:00", 2
ListsDate.Add "start", "21.01.2015 13:45:15", 1
ListsDate.Add "stop", "21.01.2015 16:15:04", 2
ListsDate.Add "start", "21.01.2015 17:30:15", 4
ListsDate.Add "stop", "21.01.2015 19:17:15", 4
ListsDate.Add "start", "21.01.2015 21:30:37", 4
ListsDate.Add "stop", "22.01.2015 02:59:15", 4
ListsDate.Add "start", "22.01.2015 03:30:55", 3
ListsDate.Add "stop", "22.01.2015 06:15:15", 3
ListsDate.Add "start", "22.01.2015 07:30:15", 1
ListsDate.Add "stop", "22.01.2015 10:15:15", 2
Мне надо подсчитать временной интервал между отметками start и stop" за определенный период. Написал код, вроде работает НО неправильно считает если конец запрашиваемого периода попадает между отметками start и stop
где закралась ошибка не знаю, уже головной моСк кипит, прошу помощи в поиске ошибки
Вот код:
П.С. здесь вместо UDT AddNewDate использую класс AddNewDate и класс-коллекцию ColNewDate, весь код в архиве
- Код: Выделить всё
Dim ListsDate As ColNewDate
Dim tmDate As AddNewDate
Dim minOn As Integer
Dim minOFF As Integer
Sub addd()
On Error GoTo ErrorHandler
Set ListsDate = New ColNewDate
Set tmDate = New AddNewDate
'=============================================================
ListsDate.Add "start", "21.01.2015 08:30:15", 1
' ListsDate.Add "stop", "21.01.2015 09:50:15", 1
ListsDate.Add "stop", "21.01.2015 10:15:15", 2
ListsDate.Add "start", "21.01.2015 11:55:05", 1
ListsDate.Add "stop", "21.01.2015 13:20:00", 2
ListsDate.Add "start", "21.01.2015 13:45:15", 1
ListsDate.Add "stop", "21.01.2015 16:15:04", 2
ListsDate.Add "start", "21.01.2015 17:30:15", 4
ListsDate.Add "stop", "21.01.2015 19:17:15", 4
ListsDate.Add "start", "21.01.2015 21:30:37", 4
ListsDate.Add "stop", "22.01.2015 02:59:15", 4
ListsDate.Add "start", "22.01.2015 03:30:55", 3
ListsDate.Add "stop", "22.01.2015 06:15:15", 3
ListsDate.Add "start", "22.01.2015 07:30:15", 1
ListsDate.Add "stop", "22.01.2015 10:15:15", 2
'=============================================================
Exit Sub
ErrorHandler:
MsgBox Error, vbExclamation + vbOKOnly
End Sub
Sub tipBDLoad(Optional ByVal Index As Integer = 0, Optional ByVal tmn1 As Date, Optional ByVal tmn2 As Date, Optional ByVal txt As String)
' On Error Resume Next
Dim stp As Boolean, e1 As Boolean, tmp As Date, tmp1 As Long
Dim strlDate As String
Dim I As Integer, lastindex As Integer
Dim y As Integer
Dim b1 As Boolean, b0 As Boolean, e0 As Boolean
Dim tempmax1 As Integer, S As Long, tmplastOn, Work As Long, sCount, sekOn As Long, sekOff As Long, NotWork As Long, lDate, lDateerr, lsrt
S = 0
tmplastOn = False
sekOn = 0
sekOff = 0
stp = True
For Each tmDate In ListsDate
I = I + 1
' перебераем коллекцию записей
' .
If tmDate.Parametrs = "start" And stp = True Then
b1 = True
stp = False
lDate = tmDate.Dates
strlDate = tmDate.Dates
tempmax1 = tmDate.Num
End If
If tmDate.Parametrs = "stop" And b1 = True Then
sekOn = sekOn + DateDiff("s", lDate, tmDate.Dates)
b1 = False
lsrt = (tmDate.Dates)
stp = True
End If
If CDate(ListsDate(I).Dates) >= CDate(tmn2) Then
lastindex = I
Exit For
End If
Next
If ListsDate(lastindex).Parametrs = "start" Then
tmp1 = DateDiff("s", lDate, tmn2)
sekOn = sekOn + tmp1
End If
If ListsDate(lastindex).Parametrs = "stop" And CDate(ListsDate(lastindex).Dates) > CDate(tmn2) Then
tmp1 = DateDiff("s", tmn2, ListsDate(lastindex).Dates)
sekOn = sekOn - tmp1
End If
tmp1 = DateDiff("s", tmn1, tmn2)
sekOff = tmp1 - sekOn
If sekOn > 0 Then
Work = sekOn \ 60 '+ minOn
Else
Work = 0
End If
If sekOff > 0 Then
NotWork = sekOff \ 60 '+ minOFF
Else
NotWork = 0
End If
' If Work >= 1440 Then Work = 1439
'' If NotWork >= 1440 Then NotWork = 1439
Text1.Text = Text1.Text & vbNewLine
Text1.Text = Text1.Text & vbNewLine & "Время работы за " & txt & Format(TimeSerial(0, Work - minOn, 0), " hh ч. mm мин.")
Text1.Text = Text1.Text & vbNewLine & "Время простоя за " & txt & Format(TimeSerial(0, NotWork - minOFF, 0), " hh ч. mm мин.")
minOn = Work
minOFF = NotWork
End Sub
Private Sub Command1_Click()
' On Error GoTo ErrorHandler
Call addd
minOn = 0
minOFF = 0
Text1.Text = ""
Call tipBDLoad(, "21.01.2015 08:00:00", "21.01.2015 14:00:00", " за 1 смену")
Call tipBDLoad(, "21.01.2015 08:00:00", "21.01.2015 20:00:00", " за 2 смену")
Call tipBDLoad(, "21.01.2015 08:00:00", "22.01.2015 02:00:00", " за 3 смену - вот тут неправильно считает")
Call tipBDLoad(, "21.01.2015 08:00:00", "22.01.2015 08:00:00", " за 4 смену")
Text1.Text = Text1.Text & vbNewLine
Text1.Text = Text1.Text & vbNewLine & "Время работы за " & Format(TimeSerial(0, minOn, 0), " hh ч. mm мин.")
Text1.Text = Text1.Text & vbNewLine & "Время простоя за " & Format(TimeSerial(0, minOFF, 0), " hh ч. mm мин.")
Exit Sub
ErrorHandler:
MsgBox Error, vbExclamation + vbOKOnly
End Sub