:: Source code for page05.html
Home Tutorial Page 5

Here's the XML code for "page05.html":

  1:<rexxtags:page title="Writing a simple calendar tag" type="Tutorial">
  2:<p style="text-align:justify"> Let's try to write a tag which is more complicated
  3:  (and useful) than in the preceding sections. We will learn of to write a tag
  4:  which creates calendars. For example, here's a calendar for the current month:</p>
  6:<p style="text-align:justify">Here's the code used to create the calendar:<br />
  7:  <rexxtags:xmlhighlight lineno="yes"> <rexxtags:cal1/> </rexxtags:xmlhighlight>
  8:  <br />
  9:  <br />
 10:  We'll need to write a <font face="Courier New, Courier, mono">rexxtags.cal1.tag</font>
 11:  tag procedure (we call it <font face="Courier New, Courier, mono">'cal1'</font>
 12:  because we'll build more sophisticated versions of this tag later). The tag
 13:  doesn't need any parameter, and we only need to produce output for the start
 14:  tag call. The main routine will thus be:
 15:<br />
 16:<rexxtags:rexxhighlight lineno="yes">
 17:Parse arg verb
 19:  If verb = 'START' Then Signal StartTag
 20:  If verb = 'END' Then Return ''
 22:Return 0
 24:<br />
 25:<br />
 26:and we'll put all the code in 'StartTag'. If we want our tag to work properly in most versions
 27:  of Rexx (including old versions of OS/2 Warp 3.0 and 4.0 or WSeB without fixpacks),
 28:  we can't count on having date arithmetic built-in. We'll use <a href="">Rex
 29:  Swain</a>'s B2MMDDYY and MMDDYY2B and copy them into the code for our tag.</p>
 30:<p style="text-align:justify">Next we'll need a routine to calculate what's the
 31:  weekday for day 1 of a given month:<br />
 32:<rexxtags:rexxhighlight lineno="yes">
 33:DayOfWeekOfDay1: Procedure
 34:  Parse Arg mm'/'.'/'yy
 35:Return (mmddyy2b(mm'/1/'yy) // 7) + 1
 37:<br />
 38:<br />
 39:And another one to calculate what's the last day in the month:
 40:<br />
 41:<rexxtags:rexxhighlight lineno="yes">
 42:LastDayInMonth: Procedure
 43:  Parse Arg mm'/'.'/'yy
 44:  mm = mm + 1
 45:  If mm > 12 Then Do
 46:    yy = yy + 1
 47:    mm = 1
 48:  End
 49:  Parse Value b2mmddyy(mmddyy2b(mm'/1/'yy)-1) With '/' lastday '/'
 50:Return lastday
 52:<br />
 53:<br />
 54:  Now the 'StartTag' part is standard REXX. You can find the <a href="/samples/rexxtags.cal1.html">tag
 55:  code</a> in the <a href="/samples">samples</a> section. </p>

Last update: 29/12/11 at 14:22
Valid XHTML 1.0! Valid CSS!