Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Change label text every 2 weeks

Posted on 2014-09-03
Medium Priority
131 Views
I will explain this best way I can.  I am designing a piece of software for the department I work in. In the department, there are 3 teams, and 3 shifts.  Team A,B,C and the shift times are 0630-1500, 1430-2300, 2230-0700.  We rotate every 2 weeks to another shift.

Example: 8-24-2014 to 9-06-2014 A team is 1430-2200, B team is 2230-0700, C team is 0630-1500.
The teams will rotate on 9-07-2014 to 09-20-2014.  So then A team is 2230-0700, B team is 0630-1500, C team is 1430-2200.

This happens every 2 weeks.  I need to make a label that will look at the time and date and know what team is on what shift.  I do not have any code to start with, and I am not asking for code, I am asking for a starting point.  I can not wrap my head around how to even start coding this.  I have made a lot of programs and have never ran into this before.  Any help would be greatly appreciated!!  If I did not make sense or need more of a description please let me know.  Thanks in advance!  I know vb.net fairly well, but do not know c++
0
Question by:russell12
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2
• 2

LVL 35

Accepted Solution

Dan Craciun earned 1000 total points
ID: 40302501
Store the shifts in an associative array (dictionaries in VB):
week1 = {teamA:"06:30", teamb:"14:30", teamc:"22:30"}
week2 = {teamA:"06:30", teamb:"14:30", teamc:"22:30"}
week3 = {teamA:"22:30", teamb:"06:30", teamc:"14:30"}
and so on.
week6 = {teamA:"14:30", teamb:"22:30", teamc:"06:30"}

Basically you repeat every 6 weeks. Get the week number (calendar.GetWeekOfYear), divide by 6, get the remainder and you'll know what team is on what shift.

HTH,
Dan
0

LVL 2

Author Comment

ID: 40302570
Thank you for the quick response.  This definitely helps, it is pointing me in the right direction!!  The only thing that I an not understanding is lets say we are on week 20.  If you take 20/6 you get 3.3333333.  The array will not match to lets say week "3".  I do have the following code written from the example you gave me:

``````    Dim myCI As New CultureInfo("en-US")
Label30.Text = myCI.Calendar.GetWeekOfYear(DateTime.Now, 0, DayOfWeek.Sunday)
If Label30.Text <= 1 Or Label30.Text >= 2 Then
Label4.Text = 1
Exit Sub
End If
If Label30.Text <= 3 Or Label30.Text >= 4 Then
Label4.Text = 2
Exit Sub
End If
If Label30.Text <= 5 Or Label30.Text >= 6 Then
Label4.Text = 3
Exit Sub
End If
``````

I may not be thinking of the math in the proper way, but for example on the next rotation we will be in week 37.  If you take 37/6 you get 6.17.  If you subtract 2 from that you get 4.17.  Then the next rotation happens on week 39.  If you take 39/6-2 you get 4.5.  I sure I am missing something very small.  Thanks again for your help!!
0

LVL 35

Expert Comment

ID: 40302613
You need the remainder. 20/6 is 3, remainder 2. This means you're on week 2 (or 3, if you choose to not start from 0).
On week 37, you get remainder 1, which means you're on week 1 again. This keeps repeating:
18 - week 0
19 - week 1
20 - week 2
21 - week 3
22 - week 4
23 - week 5
24 - week 0 again, and so on

In VB I think it's called Mod the operator, so you'll get something like this:
if weekno Mod 6 = 0 then do whatever you want with week 0
if weekno Mod 6 = 1 etc
0

LVL 15

Assisted Solution

ID: 40302740
Do you work 7 day weeks or 5 day weeks (Mon - Fri), as this will affect what is required on the first day of the week.

If you work a 7 day week then the time prior to 06:30 on day 1 of the week is actually the last shift from the previous week, so you should subtract 6.5 hrs from the local time.

Also, what happens at the end of the year, some years have 53 weeks, so what you really need to do is work out the number of weeks since a starting date. This is done using DateDiff

NumberOfWeeks = DateDiff(DateInterval.WeekOfYear, BaseDate, OffsetTime)

You can then work out the shift pattern using the Mod function as previously suggested

ShiftPattern = NumberOfWeeks Mod 6

This will return 0 or 1 for pattern 1, 2 or 3 for pattern 2 and 4 or 5 for pattern 3
0

LVL 2

Author Comment

ID: 40304895
I did not even think of that.  You are absolutely correct about this.  Our department works 5 (M-F) days when its not peak season and 6 (M-Sat) days during peak season.  The kicker to all this is the team that works the 2230-0700 comes in on Sunday night at 2230.  The plant considers this as Monday.  I have never worked for a company that did it this way.  Doing the DateDiff formula would actually compensate for the leap years right?  I would use the start date 09-07-2014.  Thanks to the both of you for helping me through this.  I am working on trying to get the code together and written up.  Also one question for you and this is probably a common sense question, but what is the "BaseDate"?  That's the only part I am stuck on.  I tried DateTime.Now but I am getting a 0.  The code I tried is:

``````        Dim numberofweeks As Integer
Dim offsettime As DateTime
numberofweeks = DateDiff(DateInterval.WeekOfYear, DateTime.Now, offsettime)
MsgBox(numberofweeks)
``````

Dan Craciun:

Thank you for all your help!!  I am pulling the correct week number with your solution!!  I appreciate you not just giving me the answer and working with me.  That's how I learn!!!
Thanks again!!
Russell
0

LVL 15

Expert Comment

ID: 40305224
Base date would be the stardate. So this would be whatever you want, but would need to be the Monday of a week 1. So if next Monday was the start of week 1, base date would be

BaseDate = New Date(2014,9,8,0,0,0)

It is not Now, as otherwise you would always be in week 1

Rather than deducting 6.5 you should add 1.5. This will mean that 22:30 on the Sunday night is calculated as 00:00, and everything else is calculated from there.
0

LVL 2

Author Closing Comment

ID: 40306652
Dan Craciun :
Thank you for all your help!!  You pointed me in the right direction and I am thankful for this!!

Thank you for joining in and adding your knowledge with this.  You helped a lot also!!

I wish I could give you both 500 points each.  Both answers are the best answer!  Thanks a lot!!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
###### Suggested Courses
Course of the Month8 days, 15 hours left to enroll