I'm working on a project where I need to analyse availability of staff based on 15-minute time periods, their language skills and their shifts. I have one sheet that looks like this:
--Time-------English------German-----French
--06:15--------0------------0-----------0
--06:30--------0------------0-----------0
--06:45--------0------------0-----------0
And another one that looks like this:
--Name-----Language-----Info--------Shift--------
--Joe B----English-----BlaBla---05:45 - 12:30---
--Al C-----English-----BlaBla---07:45 - 15:30---
--Jill T---English-----BlaBla---07:45 - 15:30---
So, I need to take the Language they speak, their shift (split into start and end times) and based on the language specified in the heading of that column (in the first sheet given above) add '1' if they speak that language and are available at that time.
Below is the code I have at present which is not doing this for me:
Function CalculateAvailability(The_Time As String, The_Info As Range, Current_Lang As String)
'The_Time is the current 15-minute period
'The_Info is the range of fields in sheet 2 with our information (A3:D5 above)
'Current_Lang is the current language heading
Dim The_Lang As String 'the language of the staff member
Dim The_Shift_Start As String 'obvious
Dim The_Shift_End As String 'also obvious
Dim stGotIt As String 'redundant, not used currently
Dim stCell As String 'for capturing the cell contents
Dim Counter As Integer 'our counter
Counter = 0
For Each r In The_Info.Rows
For Each c In r.Cells
stCell = c.Value
If InStr(1, stCell, ":", vbTextCompare) > 0 Then
The_Shift_Start = GetShiftStart(stCell) 'this code works
The_Shift_End = GetShiftEnd(stCell) 'this code works
开发者_如何学运维 End If
If InStr(1, stCell, Current_Lang, vbTextCompare) > 0 Then
The_Lang = Current_Lang 'seems redundant but how else to do the check?
Counter = 17 'test value - doesn't seem to reach here
End If
Next c
If The_Lang = Current_Lang Then
Counter = 5 'test value - doesn't seem to reach here either
End If
Next r
CalculateAvailability = "Time:" + The_Time + " - Start:" + The_Shift_Start + " - End:" + The_Shift_End + " - Avail. " + Counter 'for output purposes
End Function
It doesn't seem to be reaching the important parts of my code where I would do the calculation that calls a seperate (tested and working) function that returns '1' or '0' based on the time period and the shift start and end times. (That would be where I specify Counter = 5) Is my logic in the code above incorrect? I realise that the testing of the language seems redundant and is probably incorrect, but as the commenting says, I couldn't rework that more sensibly. One thing I'm curious about is does the For Loop immediately jump from the "Next" back to the related "For Each" or does it carry out the following code and THEN jump back up? (I know this wouldn't make much sense programmatically, but I'm not that familiar with VB so I can't say for sure, despite how ridiculous it seems in light of my C/C#/C++ knowledge)
All help greatly appreciated!
Assuming that Current_Lang
is not sent in as an empty string and the code never reaches the line Counter = 17
, it will never reach the line Counter = 5
either, so I think you can concentrate on why it doesn't reach Counter = 17
.
The most likely answer to that would seem to be that stCell
does not contain what you expect it to contain and so this is the reason why it can't find Current_Lang
in there. Try to output or Watch
what's in stCell
so you can check why it's not working.
精彩评论