Solved

Change label text every 2 weeks

Posted on 2014-09-03
7
122 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now