Hello Rebol,this had a few errors and fixed:
REBOL [
   Title:  "HTML Monthly Calendar"
   Date:   19-Feb-2000
   Version: 0.0.1
   Name:   "Monthly Calendar"
   File:   %rebMonth.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 }
]
; initialize

weekdays: [Monday Tuesday Wednesday Thursday Friday Saturday Sunday]
; weeks in this calandar 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 "HTMLCalendar.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 intrested in is " PICK
months(firstOfMonth/month) year"?"]

; 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 previos 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 follwing back to the
client, after evaluation of course?

ECHO  %rebolcal.htm ; write output to a file


; how do I surpress the 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 rebolcal.htm </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.

  IF (off > 7) [PRINT "<tr>" off: 1] ; used to start the each week after
the first

  ; at the very start of the month we might need to fill in table cells.
  IF day = 1 [
 ; print preceeding 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, preceed 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

  PRINT ["<td valign='top' halign='left' height='100' width='100'><font
face='Arial' color='red'>"day "</font></td>"]


  ; 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]
 ] [
 PRINT ""
        ] ; end EITHER

] ; 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


Regards
-- 
JMS Trustee http://www.jms.org
HP=http://www.sonic.net/~alanwall/
First computer solar powered vic-20
AmigaQNX-notAmigaNG=no good
computers for people not suits
sent via Yam ver2 on AmigaForever ver3
UIN=9391028

Reply via email to