A strange bug (?) with calendar (from the Scripter's Scrapbook)

FlexibleLearning at aol.com FlexibleLearning at aol.com
Mon Mar 8 11:09:45 EST 2004


In a message dated 08/03/2004 14:21:00 GMT Standard Time, 
use-revolution-request at lists.runrev.com writes:

> Message: 9
> As an exercise, I tested the script given in the Scripter's Scrapbook:
> 
> =====
> on mouseUp
>  put calendar(Apr,1995) into cd fld "Calendar"
> end mouseUp


Try this which we have found rather more satisfactory. It gives a calendar in 
your own language, the week beginning on any day. Give it 3 bits of 
information and it gives you a calendar...

on mouseUp
  # Gives a language-localized calendar with selectable first day of week.
  # Syntax: FLCcalendar (<startDay 1-7>, <Month 1-12>,<Year 1970-2037>)
  put FLCcalendar(3,1,2004) into cd fld "Calendar"
end mouseUp

function FLCcalendar tStartDayNum,tM,tY
  put the system monthNames into tMonthNames
  get the abbrev system WeekDayNames
  repeat for each line L in it
    if len(L) is 2 then put space & L into L
    put char 1 to 3 of L &cr after tAbbrevWeekDayNames
  end repeat
  delete last char of tAbbrevWeekDayNames
  # Verify params...
  put tM &"/1/"& tY into tCalendarMonth
  convert tCalendarMonth to dateItems
  if the result <>"" then return "Date error"
  put item 1 of tCalendarMonth into tY
  put line (item 2 of tCalendarMonth) of tMonthNames && tY into monthHeader
  # Build Calendar day header line, starting from selected day of the week...
  put tAbbrevWeekDayNames into dayHeader
  put (line tStartDayNum to -1 of dayHeader)&cr&(line 1 to tStartDayNum -1 of 
dayHeader) into dayHeader
  replace cr with space in dayHeader
  # To centre the monthHeader...
  put char 1 to round((length(dayHeader)-length(monthHeader)) div 2) +1 of "  
                  " before monthHeader
  # Build Calendar...
  put empty into days
  if tStartDayNum is 1 then put 7 into tEndDayNum
  else put tStartDayNum -1 into tEndDayNum
  # Calculate position of first date...
  put (item 7 of tCalendarMonth) - (tStartDayNum)+1  into dayOffset
  if dayOffset < 1 then put (7+ dayOffset) into dayOffset
  repeat with dayNum = 1 to dayOffset -1
    put "    " after days
  end repeat
  # Complete Calendar...
  repeat while item 2 of tCalendarMonth is tM
    get " " & item 3 of tCalendarMonth & " "
    if length(it) is 3 then get " " & it
    if item 7 of tCalendarMonth is tEndDayNum then get it & cr
    put it after days
    add 1 to item 3 of tCalendarMonth
    convert tCalendarMonth from dateItems to long system date -- to force 
next line to update
    convert tCalendarMonth from long system date to dateItems
  end repeat
  return monthHeader & cr &  dayHeader & cr & days
end FLCcalendar

/H


More information about the use-livecode mailing list