Hey guys,
I wrote a vb.net code where I'm going to guess which shift I'll be working on a working cycle like
5 afternoon shifts
1 day off
5 morning shifts
1 day off
5 night shift
1 day off
and so forth
But I'm trying to replicate it for b4x but to be honest, I literally don't know where to start :\
Would someone mind to help me?
Much thanks..
Code
I wrote a vb.net code where I'm going to guess which shift I'll be working on a working cycle like
5 afternoon shifts
1 day off
5 morning shifts
1 day off
5 night shift
1 day off
and so forth
But I'm trying to replicate it for b4x but to be honest, I literally don't know where to start :\
Would someone mind to help me?
Much thanks..
Code
B4X:
Public Class Form1
Private Sub DisplayShifts()
Dim startdate = New DateTime(2022, 12, 24)
Dim selectedDate = DateTimePicker1.Value
Dim shift = GetShift(startdate, selectedDate)
MsgBox(shift.ToString())
End Sub
Function GetShift(startDate As Date, selectedDate As Date) As ShiftKind
Dim days = (selectedDate - startDate).TotalDays
Dim intervals = days \ 18
Dim normalizedSelected = selectedDate.AddDays(intervals * -18)
days = (normalizedSelected - startDate).TotalDays
Select Case days
Case 0 To 4
Return ShiftKind.Afternoon
Case 6 To 10
Return ShiftKind.Morning
Case 12 To 16
Return ShiftKind.Night
End Select
Return ShiftKind.Off
End Function
Public Structure Shift
Public Property StartDate As Date
Public Property EndDate As Date
Public Property Kind As ShiftKind
Public Function Contains(value As Date) As Boolean
Return value >= StartDate AndAlso value <= EndDate
End Function
Public Overrides Function ToString() As String
Return $"{StartDate} - {EndDate} : {Kind}"
End Function
End Structure
Public Enum ShiftKind
Off = 1
Morning
Afternoon
Night
End Enum
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
DisplayShifts()
End Sub
End Class