'----------------------------------------------------------------------------
SUB IncDate(Yr%,WeekDay$,MonDate$,WkDayDate$)
'Accepts Yr% as integer of year involved -- thus 2013
'Accepts Weekday$ as 3 digit string of the weekday, the date of which
' is required -- thus "Wed", "Thu" or "Fri"
'Accepts MonDate$ as the 6 digit string of the date of the Monday of
' the week -- thus " 1 Jul" or "23 Sep"
'Returns WkDayDate$ as a similar 6 digit string date of the required weekday.
IF Yr% <> OldYr% THEN
DDat$ = "MonTueWedThuFriSatSunJan3Feb0Mar3Apr2May3Jun2Jul3Aug3Sep2Oct3Nov2Dec3"
CALL LeapYr(Yr%, LY%)
IF LY% = 1 THEN MID$(DDat$,29,1) = "1"
OldYr% = Yr%
END IF
IF WeekDay$ = "Mon" THEN WkDayDate$ = MonDate$:EXIT SUB 'Subroutine not needed
IF WeekDay$ = "W/c" THEN WkDayDate$ = MonDate$:EXIT SUB 'Subroutine not needed
IF WeekDay$ = "W/C" THEN WkDayDate$ = MonDate$:EXIT SUB 'Subroutine not needed
WkDayDate$ = MonDate$ 'WkDayDate$$ = MonDate$ ready for modification
' avoiding concatination
'NB: Month string correct if new date
' is in same month
i% = (INSTR(DDat$,WeekDay$) + 2)/3 - 1 'i% is the required weekday number
'thus i% = 3 for "Wed"
Dy% = INT(VAL(MonDate$)) + i% 'Increment the date to the required
'weekday
Mn$ = MID$(MonDate$,4,3) 'Mn$ is 3 alpha Month
Mn% = (INSTR(DDat$,Mn$) - 18)/4 'Mn% is Month#
Me% = 28 + INT(VAL(MID$(DDat$,4*Mn% + 21,1)))
'Me% is the last day of the month
IF Dy% > Me% THEN 'If Weekday is in next month:
Mn% = Mn% + 1 'Increment Month#
MID$(WkDayDate$,4,3) = MID$(DDat$,4*Mn% + 18,3)
' & change month in output string.
Dy% = Dy% - Me% 'Reduce day# by length of previous
'month
END IF
'Then correct day# in output string
Dy$ = STR$(Dy%)
IF Dy% > 9 THEN Dy$ = MID$(Dy$,2,2) 'Two digit# to have no leading
'blanks
MID$(WkDayDate$,1,2) = Dy$
END SUB
'----------------------------------------------------------------------------
SUB LeapYr(Year%, LeapYear%)
' Accepts Year% as integer of year concerned
' Returns LeapYear% as 1 if year is leap year, 0 if not.
' (NB: I wrote this "perpetual" leap year sub routine years ago and tho'
' the penultimate line will not be used again until the year 2100
' and the last until 2400 I still use it!
LeapYear% = 0
IF Year% = 4 * INT((Year%)/4 ) THEN LeapYear% = 1 ' every 4th year
IF Year% = 100 * INT((Year%)/100) THEN LeapYear% = 0 ' unless century
IF Year% = 400 * INT((Year%)/400) THEN LeapYear% = 1 ' not divisible by 400
END SUB
'----------------------------------------------------------------------------
|