home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / orx8.zip / get_answ.cmd < prev    next >
OS/2 REXX Batch file  |  1997-07-21  |  4KB  |  129 lines

  1. /* 
  2.  
  3. copied from SHOWINI.CMD (same author) ...
  4. name of this module made compatible for FAT 
  5.  
  6.  
  7. program: get_answ.cmd
  8. type:    REXXSAA-OS/2, Object Rexx, REXXSAA 6.x
  9. purpose: utilities for dealing with LaMail and PMMail files
  10. version: 0.0.9
  11. date:    1997-02-10
  12. changed: ---
  13.  
  14. author:  Rony G. Flatscher
  15.          Rony.Flatscher@wu-wien.ac.at
  16.  
  17. needs:   ObjectRexx 
  18.  
  19. usage:   via ::REQUIRES and then call the routine:
  20.  
  21.          get answer from user, if a 3rd argument is supplied, then force an entry
  22.          ARG(1) ... string of valid letters
  23.          ARG(2) ... upper bound of an arithmetic value
  24.          ARG(3) ... if given, force user to enter at least one character
  25.  
  26. All rights reserved, copyrighted 1997, no guarantee that it works without
  27. errors, etc. etc.
  28.  
  29. You are granted the right to use this module under the condition that you don't charge money for this module (as you didn't write
  30. it in the first place) or modules directly derived from this module, that you document the original author (to give appropriate
  31. credit) with the original name of the module and that you make the unaltered, original source-code of this module available on
  32. demand.  If that holds, you may even bundle this module (either in source or compiled form) with commercial software.
  33.  
  34. Please, if you find an error, post me a message describing it, I will
  35. try to fix and rerelease it to the net.
  36. */
  37.  
  38. :: ROUTINE GET_ANSWER   PUBLIC
  39.     validLetters = ARG(1)
  40.     upperBound   = ARG(2)       /* 0 - upperBound */
  41.  
  42.     i = 0
  43.     answer = ""
  44.  
  45.     DO FOREVER
  46.        tmp = TRANSLATE(SysGetKey("noecho"))     /* get key-stroke       */
  47.  
  48.        IF tmp = "0D"x THEN                      /* CR-was pressed       */
  49.        DO
  50.           IF ARG(3) = "" | i > 0 THEN LEAVE
  51.           CALL BEEP 2000, 250
  52.           ITERATE
  53.        END
  54.  
  55.        IF tmp = "1B"x THEN                      /* Escape was pressed   */
  56.        DO
  57.           answer = tmp
  58.           LEAVE
  59.        END
  60.  
  61.        IF tmp = "08"x THEN                      /* Backspace was pressed        */
  62.        DO
  63.           IF i = 0 THEN                         /* already at first position    */
  64.           DO
  65.              CALL BEEP 2000, 250
  66.              ITERATE
  67.           END
  68.  
  69.           CALL CHAROUT , tmp                    /* backspace */
  70.           CALL CHAROUT , " "                    /* erase character */
  71.           CALL CHAROUT , tmp
  72.           i = i - 1
  73.  
  74.           IF i = 0 THEN answer = ""             /* adjust value of answer */
  75.           ELSE answer = SUBSTR(answer, 1, i)
  76.  
  77.           ITERATE
  78.        END
  79.  
  80.        IF POS(tmp, validLetters) > 0 THEN       /* a valid letter ?     */
  81.        DO
  82.           IF answer = "" THEN
  83.           DO
  84.              answer = tmp
  85.              CALL CHAROUT , answer
  86.              LEAVE
  87.           END
  88.  
  89.           CALL BEEP 2000, 250
  90.           ITERATE
  91.        END
  92.  
  93.        IF upperBound <> "" THEN                 /* number within upper bound ?  */
  94.        DO
  95.           IF i = 0 THEN
  96.           DO
  97.              IF POS(tmp, "0123456789") > 0 & tmp <= upperBound THEN
  98.              DO
  99.                 CALL CHAROUT , tmp
  100.                 answer = tmp
  101.                 i = i + 1
  102.                 IF answer = 0 | LENGTH(upperBound) = 1 | (answer || "0" > upperBound) THEN LEAVE
  103.                 ITERATE
  104.              END
  105.           END
  106.           ELSE
  107.           DO
  108.              IF POS(tmp, "0123456789") > 0 THEN
  109.              DO
  110.                 IF answer || tmp <= upperBound THEN
  111.                 DO
  112.                    CALL CHAROUT , tmp
  113.                    answer = answer || tmp
  114.                    i = i + 1
  115.  
  116.                    IF LENGTH(answer) = LENGTH(upperBound) | (answer || "0" > upperBound) THEN LEAVE
  117.                    ITERATE
  118.                 END
  119.              END
  120.           END
  121.        END
  122.  
  123.        CALL BEEP 2000, 250
  124.     END
  125.     SAY
  126.  
  127.     RETURN answer
  128.  
  129.