Here is a very basic example and will need to be expanded with a lot of additional code to handle day rollover and many other things but just to give you a concept
Class Category:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Category"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private pweekday As String
Private ptime_start As Double
Private ptime_stop As Double
Private pcategory As String
Public Property Let weekday(day As String)
pweekday = day
End Property
Public Property Let time_start(time As Double)
If checkTime(time) Then
ptime_start = time
Else
MsgBox "Start Error"
End If
End Property
Public Property Let time_stop(time As Double)
If checkTime(time) Then
ptime_stop = time
Else
MsgBox "Stop Error"
End If
End Property
Public Property Let category(cat As String)
pcategory = cat
End Property
Public Sub setup(cat As String, day As String, t_start As Double, t_stop As Double)
If checkTime(t_start) And checkTime(t_stop) Then
pcategory = cat
pweekday = day
ptime_start = t_start
ptime_stop = t_stop
Else
MsgBox "SetupError"
End If
End Sub
Public Property Get category() As String
category = pcategory
End Property
Public Property Get weekday() As String
weekday = pweekday
End Property
Public Property Get time_start() As Double
time_start = ptime_start
End Property
Public Property Get time_stop() As Double
time_stop = ptime_stop
End Property
Private Function checkTime(time As Double) As Boolean
checkTime = time <= 24 And time >= 0
End Function
Class TimeTable
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "TimeTable"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private ptime_table As New Collection
Public Sub add(cat As String, day As String, t_start As Double, t_stop As Double)
Dim addcat As New category
addcat.setup cat, day, t_start, t_stop
ptime_table.add addcat
End Sub
Public Function getStartCategory(day As String, t_start As Double, hours As Double) As String
Dim c As category
Dim c_start As String
Dim start_hours As Double
For Each c In ptime_table
If c.weekday = day Then
If t_start >= c.time_start And t_start <= c.time_stop Then
If hours > (c.time_stop - t_start) Then
start_hours = c.time_stop - t_start
Else
start_hours = hours
End If
c_start = CStr(start_hours) & ";" & c.category
End If
End If
Next c
getStartCategory = c_start
End Function
Public Function getStopCategory(day As String, t_stop As Double, hours As Double) As String
Dim c As category
Dim c_stop As String
Dim stop_hours As Double
For Each c In ptime_table
If c.weekday = day Then
If t_stop <= c.time_stop And t_stop >= c.time_start Then
If hours > (t_stop - c.time_start) Then
stop_hours = t_stop - c.time_start
Else
stop_hours = hours
End If
c_stop = CStr(stop_hours) & ";" & c.category
End If
End If
Next c
getStopCategory = c_stop
End Function
Public Function getCategory(day As String, t_start As Double, t_stop As Double) As String
Dim hours As Double
hours = hoursworked(t_start, t_stop)
c_start = getStartCategory(day, t_start, hours)
c_stop = getStopCategory(day, t_stop, hours)
getCategory = c_start & ";" & c_stop
End Function
Private Function hoursworked(t_start As Double, t_stop As Double) As Double
hoursworked = t_stop - t_start
End Function
Simple Example Module
Sub setup()
Dim tt As New TimeTable
With tt
.add "AA", "Monday", 8, 14.5
.add "AA", "Tuesday", 8, 14.5
.add "AA", "Wednesday", 8, 14.5
.add "AA", "Thursday", 8, 14.5
.add "AA", "Friday", 8, 14
.add "AB", "Monday", 14.5, 21
.add "AB", "Tuesday", 14.5, 21
.add "AB", "Wednesday", 14.5, 21
.add "AB", "Thursday", 14.5, 21
.add "AB", "Friday", 14, 21
.add "AC", "Monday", 21, 8
.add "AC", "Tuesday", 21, 8
.add "AC", "Wednesday", 21, 8
.add "AC", "Thursday", 21, 8
.add "AC", "Friday", 21, 8
.add "AC", "Saturday", 0, 24
.add "AC", "Sunday", 0, 24
End With
MsgBox tt.getCategory("Monday", 12, 18)
End Sub
This will Return "2.5;AA;3.5;AB" Meaning On Monday this person worked 2.5 hours in category AA and 3.5 hours in Category AB.
Like I said this is a simple example of how you might start and needs much more error handling, functionality and data mapping but hopefully it will get you started