oooopsss, were the html tags a bit thick last time... sorry :-\ . ; THIS version CORRECTS extra column for months whose first day lands at end of week. ; also changes name from rebMonth.r to htmMonth.r ; Please delete the rebMonth.r it's no good. REBOL [ Title: "HTML Monthly Calendar" Date: 19-Feb-2000 Version: 0.0.2 Name: "Monthly Calendar" File: %htmMonth.r Author: "John Braman" Email: [EMAIL PROTECTED] Rights: { "Copyright (C) John Braman" Permission to use and improve granted, with the understanding you include my footer on calendar. And if improvements are made please email improvements to [EMAIL PROTECTED] } Purpose: { Prelude to AN INTERACTIVE HTML MONTHLY CALENDAR. Currently, using the Rebol Console, you enter the month and year you are interested in. This code prints the html version of that month to a file called rebolcal.htm " } Comment: { Thanks to bpaddock, Olivier, Donald Dalley, Karin, rryost especially Olivier for the slick date coding, and Donald Dalley and others on list who replied to my initial 'prelude to HTML post'. Ideally future versions will be more interactive and completely cgi-enabled with a database or series in flat files. However... I need HELP HERE: The simplest of code that is intuitively obvious for veteran Rebols, is new to me. For example. I've seen several html-related scripts using an "EMIT" function, yet I don't know how it works. Ideally I'd like to retrieve values from a database or at least from a file. Much like I would with coldFusion, PERL, PHP, ASP etc. However I've not found clear examples of dbase connection. Or even less sophisticated examples of getting data from a file. There are too few good examples of using REBOL words in the dictionary. HELP ! For example: What if I had a file with 365+ records, many of which will contain the values of holidays and the like. The unique key being the date. How do I get data from that file via http? How would I write to that file for updates? How do I write to that file to update the specific record only using cgi? } History: [originally called rebMonth.r version 0.0.1 created 19-2-2000 This version called htmMonth.r created 27-2-2000] Example: {Show how to use it.} ] ;;;;;;;;;;;; BODY OF CODE FOLLOWS ;;;;;;;;;;;;; ; initialize weekdays: [Sunday Monday Tuesday Wednesday Thursday Friday Saturday] ; weeks in this calendar start with Monday, if you want them to start with any other day then use the series or offset to the appropriate day of week. Or change this block to start with the day of the week that you want it to. months: [January February March April May June July August September October November December] ; get month and year from user userDate: PARSE ASK " Enter Month as MM YYYY, or q to exit : " NONE IF (first userDate) = "q" [ PRINT "rebMonth.r" HALT ] ; use appropriate datatype month: MAKE INTEGER! FIRST userDate year: MAKE INTEGER! SECOND userDate ; join the input and make it to be the first day of the month inputDate: JOIN 1 [ "-" month "-" year ] firstOfMonth: MAKE DATE! inputDate PRINT ["Do I have it right, the month you are interested in is " PICK months(firstOfMonth/month) year"?" NEWLINE "Cancel the write to file and re do %htmMonth.r if it's not the right date."] ; find first of next month and first of previous month ; this will help us to find the number of days in month to make calendar firstOfNextMonth: firstOfMonth/month: firstOfMonth/month + 1 PRINT ["check again is this the month?" PICK months(firstOfMonth/month)] ; find days in month and days in previous month daysInMonth: firstOfNextMonth - firstOfMonth ; firstOfPrevMonth: firstOfMonth/month: firstOfMonth/month - 1 ; there is a bug in the above date function which doesn't work for the first month in the year. ; so do a work around. Either (month = 1) [ prevMonthName: "December" daysInPrevMonth: 31 ] [ firstOfPrevMonth: firstOfMonth/month: firstOfMonth/month - 1 daysInPrevMonth: firstOfMonth - firstOfPrevMonth ; convert previous month to words and save it. prevMonthName: PICK months (firstOfPrevMonth/month) ]; end first month bug correction ; convert the month to words, save it. monthName: PICK months (month) nextMonthName: PICK months (firstOfNextMonth/month) ; print the values just to check them PRINT ["There are " daysInPrevMonth " days in " prevMonthName ] ; adjust for first month bug PRINT ["There are " daysInMonth " days in " monthName firstOfMonth/year ] ; is it possible to echo to a port easily for cgi purposes, what is the best way if this were running on a server to get the following back to the client, after evaluation of course? ECHO %rebolcal.htm ; write output to a file ; how do I avoid printing to the console? ; HTML header of the calendar page include title and a heading with name of month. print "<html>" print "<head>" print "<title> REBOL MADE CALENDAR by John Braman's rebMonth.r </title>" print "</head>" print "<body>" print "<center><h1><font face='Arial' color='BLUE'>" print [monthName firstOfMonth/year] ; we get month from the input print "</font></h1></center>" ; Print table, heading days of week, start with Monday print "<table border='1' bordercolor='yellow' cellpadding='5' cellspacing='5' width='100%'><tr>" i: 1 while [i <= 7] [ print ["<th><b><font face='Arial color='blue'>" PICK weekdays(i) "</font></b></th>"] i: i + 1 ] ; end while for headings print "</tr>" ; Put the data into the table to form a calendar. ; Don't exceed the total number of daysInMonth. ; Initialize day: 1 ; for the days of the month i: 1 ; for figuring out where to start printing the first day of month "fdom" off: 0 ; used to keep track of where in the week we are. fdom: firstOfMonth/weekday ; set where to print first day of week. PRINT "<tr>" ; start the first weeks row WHILE [day < daysInMonth] [ off: off + 1 ; marks where in week we are so we can start new row after 7 days. ; at the very start of the month we might need to fill in table cells. IF day = 1 [ ; print preceding cells for the first week, fill with dates from prev month WHILE [i < fdom][ PRINT ["<td valign='top' halign='left' height='100' width='100'><font face='Arial' color='black'>"] PRINT [(daysInPrevMonth - fdom + i + 1)"<small><small>"prevMonthName"</small></small></font></td>" NEWLINE] ; ????????? i: 1 + i ; ???????? isn't there a short cut for incrementing values +=i? ; ????????? off: off + 1 ; advance where we are in the week ] ; end while, preceding cells are filled with end dates from previous month. ; print the first day of the month PRINT ["<td valign='top' halign='left' height='100' width='100'><font face='Arial' color='red'>1</font></td>" NEWLINE] off: off + 1 ; advance where we are in the week ] ; end IF (day = 1) day: day + 1 ; advance to next day ; OOOOPSSSS revision from 0.1 to 0.2 I moved the printing of the next day after we check for the end of the week. I was getting one extra column in the row of the first week, because I was printing the 2nd day before I checked to see if I was at the end of the week. ; Either we are at the end of the week so we print a </tr> ; Or we're not there yet so print a blank line, this keeps the html easy to read ; and continue cells for that week using the while for the month. EITHER (off > 7) PRINT ["</tr>" NEWLINE "<tr>"] off: 1 ] PRINT "" ] ; end EITHER PRINT ["<td valign='top' halign='left' height='100' width='100'><font face='Arial' color='red'>"day "</font></td>"] ] ; end while for month ; Let's show the start of the next month while printing the remaining cells in the table. IF (off < 7) [ idayNextMonth: 1 While [off < 7] [ PRINT ["<td valign='top' halign='left' height='100' width='100'>"] PRINT ["<font face='Arial' color='purple'>" idayNextMonth "<small><small>" nextMonthName "</small></small></font></td>"] off: off + 1 idayNextMonth: idayNextMonth + 1 EITHER (off > 7) [PRINT ["</tr>" NEWLINE]] [PRINT ""] ] ; end nextMonths first days While ] ; end off < 7 IF PRINT "</table>" PRINT "<center><font face='Arial' color='red'><small><small><a href=mailto:[EMAIL PROTECTED]>John Braman copyright Feb 2000<br>[EMAIL PROTECTED]</a></small></small></font></center>" PRINT ["</body>" NEWLINE "</html>"] ECHO NONE