Solved

Change label text every 2 weeks

Posted on 2014-09-03
7
129 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
[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
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 35

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 35

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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create simple VB.net Add-in for Excel in Office 365 2 60
reading an excel file vb.net 2 47
Data Analysis 7 59
Using the .NET JSON Serializer to create a single string 6 59
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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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