home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / batch / ebl407.zip / BATDEMO3.BAT < prev    next >
DOS Batch File  |  1990-11-01  |  4KB  |  97 lines

  1. BAT * Sample of advanced EBL-PLUS string and arithmetic...
  2.  
  3.     TYPE "The time in natural English is:"
  4.     TYPE
  5.  
  6. * Extract the hours, minutes, and seconds from the time.
  7. *       This is done by the PARSE command which splits the contents
  8. *       of an expression into any number of parts. Note that the
  9. *       character between each variable is ':' below. This command
  10. *       will split (ie. parse) the time such as 12:50:00 into pieces
  11. *       where the ':' character is located. The hour part is put into %H,
  12. *       the minute part is put into %M, etc. Seconds are parsed but
  13. *       not used for this exapmle.
  14.  
  15.      PARSE time() %H:%M:%1
  16.  
  17. *
  18. * Now begin to convert to an English sentence. First step is to make
  19. *       adjustments if we are leaning toward the top of the hour or
  20. *       minute. Note that the TYPE command below is followed by text
  21. *       then a ';'. The ';' indicates to show a word but not go to the
  22. *       next line. This is used here because the resulting sentence is
  23. *       built up in pieces word by word.
  24. *
  25. -Convert.time
  26.      TYPE "It's ;"                |* start building..
  27.      IF %M > 30 THEN %H += 1      |* towards an hour?
  28.      IF ( %M % 5 ) <> 0           |* about on minute?
  29.         THEN TYPE "about ;"
  30.      %M -= ( %M % 5 )             |* find apx 5 mins
  31.      %H += 0                      |* strip 0's fm hr
  32.      IF %H = 0
  33.         THEN %H = 12              |* handle midnight.
  34.      IF %H > 12
  35.         THEN %H -= 12             |* make it 12hr tim
  36.  
  37. *
  38. * After the adjustment, the minute variable %M is adjusted to the
  39. *       nearest five minutes. We will do a computed-GOTO in
  40. *       order to show the proper phrase. This is similar to a CASE
  41. *       statement in some other languages. That is, if %M contains 35,
  42. *       then GOTO -min.%M is the same as GOTO -min.35. Also note that
  43. *       several commands can be combined into a single EBL-Plus statement,
  44. *       TYPE and GOTO in this instance.
  45. *
  46.      GOTO -min.%M                 |* multi-way GOTO
  47. -min.0
  48. -min.60 %M = 0                    | GOTO -Hour
  49. -min.5  TYPE "five past ;"        | GOTO -Hour
  50. -min.10 TYPE "ten past ;"         | GOTO -Hour
  51. -min.15 TYPE "quarter past ;"     | GOTO -Hour
  52. -min.20 TYPE "twenty past ;"      | GOTO -Hour
  53. -min.25 TYPE "twenty-five past ;" | GOTO -Hour
  54. -min.30 TYPE "half past ;"        | GOTO -Hour
  55. -min.35 TYPE "twenty-five till ;" | GOTO -Hour
  56. -min.40 TYPE "twenty till ;"      | GOTO -Hour
  57. -min.45 TYPE "quarter till ;"     | GOTO -Hour
  58. -min.50 TYPE "ten till ;"         | GOTO -Hour
  59. -min.55 TYPE "five till ;"
  60.  
  61. *
  62. * Now show the hour. A different approach is demonstrated here.
  63. *       This time, we will select one word from several in a
  64. *       string by using the WORD() function. EBL-Plus has many
  65. *       advanced string and arithmetic functions to choose from.
  66.  
  67. *
  68. *       First start by building a string (for convenience) of all
  69. *       the words that can be shown. Note the use of '&=' which is
  70. *       a short-hand approach to expressions. Specifically
  71. *       the following two expressions are equivalant:
  72. *
  73. *               %N &= "eight nine ten eleven twelve"
  74. *               %N = %N & "eight nine ten eleven twelve"
  75. *
  76. *       The '&' is the operator for string concatenation.
  77. *
  78. -Hour
  79.         %N = "one two three four five six seven "
  80.         %N &= "eight nine ten eleven twelve"
  81.  
  82. *
  83. *       Now use the WORD() function to select the blank
  84. *       delimited word in %N corresponding to the hour in %H.
  85. *
  86.  
  87.         TYPE WORD(%N,%H) ;        |* show hr name
  88.  
  89. *
  90. *       Then round off the English phrase if at the top
  91. *       of the hour.
  92. *
  93.         IF %M = 0
  94.            THEN TYPE " o'clock;"  |* add if exact.
  95.         TYPE .
  96.         EXIT
  97.