In my app I've written I'm trying to determine what shift it is. The issue I'm having is that after midnight my code doesn't determine what shift it is. I think it's because my constants are assigning date and time when I hover over them even though I'm only assigning time. I'm still pretty new to .Net so I'm kind of learning on the fly. Here is my code.
Code:Dim DateAndTime As String Dim Time1 As DateTime = DateTime.Parse("06:00:00") Dim Time2 As DateTime = DateTime.Parse("14:00:00") Dim Time3 As DateTime = DateTime.Parse("22:00:00") Dim CurrentShift As String Dim i As Short DateAndTime = Now If Is1stShift(Time1, Time2) = True Then CurrentShift = "1" End If If Is2ndShift(Time2, Time3) = True Then CurrentShift = "2" End If If Is3rdShift(Time3, Time1) = True Then CurrentShift = "3" End If Public Function Is1stShift(ByVal Time1 As DateTime, ByVal Time2 As DateTime) As Boolean Return DateTime.Now.TimeOfDay >= Time1.TimeOfDay AndAlso DateTime.Now.TimeOfDay <= Time2.TimeOfDay End Function Public Function Is2ndShift(ByVal Time2 As DateTime, ByVal Time3 As DateTime) As Boolean Return DateTime.Now.TimeOfDay >= Time2.TimeOfDay AndAlso DateTime.Now.TimeOfDay <= Time3.TimeOfDay End Function Public Function Is3rdShift(ByVal Time3 As DateTime, ByVal Time1 As DateTime) As Boolean Return DateTime.Now.TimeOfDay >= Time3.TimeOfDay AndAlso DateTime.Now.TimeOfDay <= Time1.TimeOfDay End Function




Reply With Quote