REM "Function to create a calendar-style table of a month's blog entries"; REM "Note: field 'ShowBlogsFor' is of the format 2002-10"; REM "Note: View 'Calendar' lists the days for which there are entries"; tmp := @DbLookup(""; ""; "calendar"; ShowBlogsFor; 2); blogs:=@If(@IsError(tmp); ""; tmp); startDate:=@Date( @TextToNumber(@Left(ShowBlogsFor;"-")); @TextToNumber(@Right(ShowBlogsFor; "-")); 1); startDay := @Weekday( startDate ); endDate:=@Adjust(@Date( @Year(@Adjust(startDate; 0;1;0;0;0;0)); @Month(@Adjust(startDate; 0;1;0;0;0;0)); 1); 0; 0; -1; 0; 0; 0); days := @Day( endDate ); numList := "0":"1":"2":"3":"4":"5":"6":"7":"8":"9" *+ "0":"1":"2":"3":"4":"5":"6":"7":"8":"9"; dayList := @Subset(numList; days+1); html:= @Replace( "" + @Text(@Subset(dayList;-days)) + ""; "" + @Text(blogs) + ""; ""+@Text(blogs)+ "" ); cellsInRow5:= days - ( 29-startDay ); cellsInRow6:= days - ( 36-startDay ); row1:="" + @Repeat( " "; startDay-1 ) + @Implode( @Subset(html; 8-startDay) ) + ""+ @NewLine; row2:="" + @Implode( @Subset( @Subset(html; 8-startDay+7); -7) )+ ""+ @NewLine; row3:="" + @Implode( @Subset( @Subset(html; 15-startDay+7); -7) )+ ""+ @NewLine; row4:="" + @Implode( @Subset( @Subset(html; 22-startDay+7); -7) )+ ""+ @NewLine; row5:= @If( cellsInRow5 > 0; "" + @Implode( @Subset( @Subset(html; 29-startDay+7); @If(cellsInRow5>=7;-7;-cellsInRow5 ) ) )+ ""+ @NewLine; "" ); row6:= @If( cellsInRow6 > 0; "" + @Implode( @Subset( @Subset(html; 36-startDay+7); -cellsInRow6) ) + "" + @NewLine; "" ); row1 + row2 + row3 + row4 + row5 + row6