I am a newbie who works shift work and I found this code that will prin
out a shift schedule to a form. I have been trying to figure out how t
output the D's, N's and E's to label captions on a calendar made up o
42 labels but have not been able to. Any help would be appreciated
Thanks Bob
Function ShiftCode(ByVal OffSet&) As String
Const Sch = "**DDDDD**NNNNN**EEEEE"
ShiftCode = Mid$(Sch, (OffSet Mod 21) + 1, 1)
End Function
Private Sub Command1_Click()
For i = #2/1/2005# To #2/28/2005#
Print ShiftCode(i)
Next
End Sub
calendar code found on the internet
The algorithm is quite easy as long as you use a Control Array. Fo
this example, I am
using Labels and not TextBoxes for the calendar days (why would yo
allow your user to be
able to edit the day's number?). Put 42 Label controls in a Contro
Array, indexed from 0
to 41, and lay them out in order in a grid that is 7 Labels across by
Labels high. This
code (note the month is taken as an Integer, 1 to 12) will fill in th
Labels with the
appropriate numbers:
Dim StartBox As Integer
Dim LastDay As Integer
Dim TheYear As Integer
Dim TheMonth As Integer
' Calculate the Index number for the
' Label that will receive Day #1
StartBox = Weekday(DateSerial(TheYear, _
TheMonth, 1)) - 1
' Calculate the last day of the month
LastDay = Day(DateSerial(TheYear, _
TheMonth + 1, 0))
' Clear existing Labels that might not
' be overwritten with a new day number
For x = 0 To 6
Label1(x).Caption = ""
Label1(x + 28).Caption = ""
Label1(x + 35).Caption = ""
Next
' Fill in the days of the month
For x = StartBox To StartBox + LastDay - 1
Label1(x).Caption = x - StartBox + 1
Nex
-
bob90
-----------------------------------------------------------------------
Randy Birch - 31 Dec 2004 14:55 GMT
I believe this is what you're after, based on the 0 label array.
Private Sub Command1_Click()
Dim cnt As Long
cnt = -1 'reset
For i = #2/1/2005# To #2/28/2005#
cnt = cnt + 1 '=first one is 0
Label1(cnt).Caption = ShiftCode(i)
Next
End Sub

Signature
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
: I am a newbie who works shift work and I found this code that will print
: out a shift schedule to a form. I have been trying to figure out how to
[quoted text clipped - 54 lines]
: Posted via http://www.codecomments.com
: ------------------------------------------------------------------------
Rick Rothstein - 31 Dec 2004 15:52 GMT
> I believe this is what you're after, based on the 0 label array.
>
[quoted text clipped - 9 lines]
>
> End Sub
Maybe the "active" statement in the For loop should be this
Label1(cnt).Caption = Label1(cnt).Caption & vbNewLine & ShiftCode(i)
in order to preserve the day-numbers that were pre-loaded in the Labels
by the "calendar code found on the internet" (the OP quoted everything
perfectly for this except that he left out my name which, in my original
posting, was located between the text and the code sections).
Rick - MVP