home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / bazy / aa3_install / rexx / remindbirthday.arx < prev    next >
Text File  |  1997-01-29  |  8KB  |  225 lines

  1. /******************************************************************************
  2. *
  3. *    A D D R E S S A S S I S T  3
  4. *
  5. *    © 1994-97 Quarz Development / Alex H. Schneider
  6. *
  7. *******************************************************************************
  8. *******************************************************************************
  9. *
  10. *    CheckBirthdays.arx
  11. *
  12. *    Original von Frank Pecher
  13. *    Changes for AddressAssist 3 by Alex H. Schneider
  14. *                                                                      
  15. *    See Rexx/Readme.AREXX
  16. *                                                                      
  17. *    $Id:$
  18. *
  19. ******************************************************************************/
  20. /************************************************************************/
  21. /*  CheckBirthdays.rexx                        by Frank Pecher          */
  22. /*                 changes for AddressAssist 3 by Alex H. Schneider     */
  23. /*                                                                      */
  24. /*                                                                      */
  25. /*  Check for birthdays in the next few days.                           */
  26. /*                                                                      */
  27. /*  SYNTAX                                                              */
  28. /*      CheckBirthdays                                                  */
  29. /*                                                                      */
  30. /*  FUNCTION                                                            */
  31. /*      This script checks all entries of the current Address data file */
  32. /*      in AddressAssist and examines the birthday-field, checking for  */
  33. /*      birthdays in the next days. The script assumes, that birthday   */
  34. /*      data is stored in the Free4 field.                              */
  35. /*                                                                      */
  36. /*      This way forgetting your friend's, parents', aunts' and         */
  37. /*      uncles' birthdays becomes very hard;-}.                         */
  38. /*                                                                      */
  39. /*  REQUIREMENTS                                                        */
  40. /*      The date format in the birthday field must have one of the      */
  41. /*      following formats:                                              */
  42. /*          DD.MM.YYYY  like 13.08.1968                                 */
  43. /*          DD.MM.YY    like 13.08.68                                   */
  44. /*          DD.MM.      like 13.08.                                     */
  45. /*      In the first two cases, you will additionally be reminded       */
  46. /*      how old a person is going to be.                                */
  47. /*                                                                      */
  48. /*  CONFIGURATION                                                       */
  49. /*      To configure this script to your taste, edit the initialization */
  50. /*      of the two variables                                            */
  51. /*          DAYSBEFORE - the number of days you like to be reminded     */
  52. /*              before a birthday.                                      */
  53. /*          DAYSPASSED - the number of days you like to be reminded     */
  54. /*              after a birthday (good when coming home from holidays). */
  55. /************************************************************************/
  56.  
  57. DAYSBEFORE  = 21
  58. DAYSPASSED  = 5
  59.  
  60. salute   =  0
  61. last     =  1
  62. first     =  2
  63. address1 =  3
  64. address2 =  4
  65. place      =  5
  66. phone1   =  6
  67. phone2     =  7
  68. free1     =  8
  69. free2     =  9
  70. free3     = 10
  71. free4     = 11
  72. code     = 12
  73. remark1     = 13
  74. remark2  = 14
  75.  
  76. group1  = c2d(b2c('1'))
  77. group2  = c2d(b2c('10'))
  78. group3  = c2d(b2c('100'))
  79. group4  = c2d(b2c('1000'))
  80. group5  = c2d(b2c('10000'))
  81. group6  = c2d(b2c('100000'))
  82. group7  = c2d(b2c('1000000'))
  83. group8  = c2d(b2c('10000000'))
  84. group9  = c2d(b2c('100000000'))
  85. group10 = c2d(b2c('100000000')) * group2
  86.  
  87.  
  88. /*************************************************************************
  89. **  main
  90. */
  91. if ~show(ports, "ADDRESSASSIST.1") then
  92. do
  93.     say "Start AddressAssist first."
  94.     exit 0
  95. end
  96.  
  97. options RESULTS
  98.  
  99. today = date(i)
  100. thisyear = substr(date(s), 1, 4)
  101.  
  102. address "ADDRESSASSIST.1" dialogbox 'ControlString="OK"' 'This script reminds for birthdays in the next ' || DAYSBEFORE || ' and the passed ' || DAYSPASSED || ' days.\n\nNote: it is assumed that the birthday data is located in the *Free4* field and\nuses one of the following formats: DD.MM.YYYY, DD.MM.YY or DD.MM. .'
  103.  
  104. do while RC = 0
  105. address "ADDRESSASSIST.1" getnumofrecords
  106.  
  107. nrecord = result
  108.  
  109. do i=0 FOR nrecord
  110.  
  111.     call getrecord i
  112.  
  113.     bday = record.free4
  114.  
  115.     if bday ~= "" then
  116.     do
  117.         birthday = ConvDate(bday, thisyear)
  118.  
  119.         firstname = record.first
  120.         lastname  = record.last
  121.  
  122.         if birthday ~= 0 then
  123.         do
  124.             firstname = record.first
  125.             lastname  = record.last
  126.             diff = birthday - today
  127.  
  128.             if right(record.free4, 1) = "." then
  129.             do
  130.                 howold = ""
  131.                 st     = ""
  132.             end
  133.             else
  134.             do
  135.                 howold = right(thisyear, 2) - right(record.free4, 2)
  136.                 if howold < 0 then
  137.                     howold = howold + 100
  138.  
  139.                 howlast = right(howold, 1)
  140.  
  141.                 select
  142.                     when howlast = 1 then st = "st "
  143.                     when howlast = 2 then st = "nd "
  144.                     when howlast = 3 then st = "rd "
  145.                     otherwise             st = "th "
  146.                 end
  147.             end
  148.  
  149.  
  150.             if (diff = 1) | (diff = -1) then
  151.                 days = "day"
  152.             else
  153.                 days = "days"
  154.  
  155.             if (diff > 0) & (diff < DAYSBEFORE) then do
  156.                notice = "In "diff days" is "|| firstname " " || lastname||x2c(27)"s "howold||st"birthday."
  157.                address "ADDRESSASSIST.1" dialogbox 'ControlString="Continue"' notice
  158.            end
  159.             if (diff = 0) then do
  160.                 notice =  "*** Today is "firstname lastname||x2c(27)"s "howold||st"birthday. ***"
  161.                 address "ADDRESSASSIST.1" dialogbox 'ControlString="Continue"' notice
  162.             end
  163.  
  164.             if (diff < 0) & (-diff < DAYSPASSED) then do
  165.                 notice = diff * (-1) days" ago was "firstname lastname||x2c(27)"s "howold||st"birthday."
  166.                 address "ADDRESSASSIST.1" dialogbox 'ControlString="Continue"' notice
  167.             end
  168.  
  169.  
  170.         end
  171.     end
  172.  
  173. end
  174.  
  175. address "ADDRESSASSIST.1" dialogbox "No more birthdays found!"
  176. /* Enable listview refresh */
  177.  
  178. exit 0
  179.  
  180.  
  181. /******************************************************************************
  182. **  ConvDate()
  183. */
  184. ConvDate: procedure
  185.     arg bday,thisyear
  186.  
  187.     parse VAR bday day"."month"."year
  188.  
  189.     if length(day) < 2 then
  190.         day = 0||day
  191.  
  192.     if length(month) < 2 then
  193.         month = 0||month
  194.  
  195.     bd = thisyear||month||day
  196.  
  197.     return date(i, bd, s)
  198.  
  199.  
  200. /******************************************************************************
  201. *
  202. *    SUBROUTINE to retrieve record data in compound variable
  203. *
  204. ******************************************************************************/
  205.  
  206. getrecord:
  207.    arg n
  208.  
  209.    address "ADDRESSASSIST.1" getrecorddata last R n
  210.    record.last = result
  211.    address "ADDRESSASSIST.1" getrecorddata first R n
  212.    record.first = result
  213.    address "ADDRESSASSIST.1" getrecorddata free1 R n
  214.    record.free1 = result
  215.    address "ADDRESSASSIST.1" getrecorddata free2 R n
  216.    record.free2 = result
  217.    address "ADDRESSASSIST.1" getrecorddata free3 R n
  218.    record.free3 = result
  219.    address "ADDRESSASSIST.1" getrecorddata free4 R n
  220.    record.free4 = result
  221.    address "ADDRESSASSIST.1" getrecorddata code R n
  222.    record.code = result
  223.  
  224.    return
  225.