Solved

Change label text every 2 weeks

Posted on 2014-09-03
7
125 Views
Last Modified: 2014-09-05
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
Comment
Question by:russell12
  • 3
  • 2
  • 2
7 Comments
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 250 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

by:russell12
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

Open in new window


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 34

Expert Comment

by:Dan Craciun
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 15

Assisted Solution

by:ChloesDad
ChloesDad earned 250 total points
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.

OffsetTime = now.addhours(-6.5)

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

by:russell12
ID: 40304895
ChloesDad
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
        OffsetTime = Now.AddHours(-6.5)
        numberofweeks = DateDiff(DateInterval.WeekOfYear, DateTime.Now, offsettime)
        MsgBox(numberofweeks)

Open in new window


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

by:ChloesDad
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

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

ChloesDad :
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Gridview selected row 9 44
VB.net Open Folder in Windows Explorer 3 29
.NET 2008 VB and C# 6 27
Calculate number of nights between two dates 5 19
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question