home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / 123rexx.zip / REXXPRSE.CMD < prev   
OS/2 REXX Batch file  |  1991-10-21  |  5KB  |  80 lines

  1. /*****************************************************************************/
  2. /* Lotus 1-2-3 For OS/2 sample macro command.                                */
  3. /*                                                                           */
  4. /* {REXXRV "REXXPRSE.CMD",range1,range2}                                     */
  5. /*                                                                           */
  6. /* Intelligently parse a column of strings ('range1') into a range of cells  */
  7. /* ('range2').                                                               */
  8. /*                                                                           */
  9. /* {REXXRV "REXXPRSE.CMD logFileName",range1,range2}                         */
  10. /*                                                                           */
  11. /* Writes any TRACE or SAY output to a log file named 'logFileName'.         */
  12. /*                                                                           */
  13. /* In spreadsheets one often has a table of numbers labeled on the left.     */
  14. /* This macro creates such a table from a column of strings, in which the    */
  15. /* number are separated by blanks.  Such a column of strings can be created  */
  16. /* by pasting a table of numbers from the clipboard.                         */
  17. /*                                                                           */
  18. /* The strategy below is to parse each string from the right, stopping when  */
  19. /* the first non-numeric value is reached.  See the REXXLINK.WG2 file for a  */
  20. /* usage example.                                                            */
  21. /*                                                                           */
  22. /* Copyright (c) 1991 Lotus Development Corporation.  This code is supplied  */
  23. /* on an 'as is' basis as an example only.  This code has only received      */
  24. /* informal testing by Lotus.  Permission is granted  to copy and modify     */
  25. /* this code to your heart's content.  No warrenties expressed or implied.   */
  26. /* Remember, your mileage may vary.  Let us know if you find support of REXX */
  27. /* by 1-2-3 useful.                                                          */
  28. /*****************************************************************************/
  29.  
  30. ARG inRange, outRange
  31. IF inRange <> "RANGE1" | outRange <> "RANGE2" THEN DO
  32.    CALL Display123Error "Arguments to REXXADD.CMD are not ranges."
  33.    RETURN
  34.    END
  35. PARSE VAR range1.0 cells sheets cols rows
  36. IF sheets > 1 | cols > 1 THEN DO          /* quit if too many sheets or cols */
  37.    CALL Display123Error "range1 must lie in 1 column on 1 sheet."
  38.    RETURN
  39.    END
  40. DO row = 1 TO cells                   /* loop through the cells of the range */
  41.    foundNum = 'no'         /* have not found a numeric value in this row yet */
  42.    parsedIndex = 0
  43.    DO i = Words(range1.row) TO 1 BY -1      /* parse this row from the right */
  44.       thisWord = Word(range1.row, i)
  45.       IF Datatype(thisWord) = "NUM" THEN DO         /* this word is a number */
  46.          parsedIndex = parsedIndex + 1
  47.          parsedValue.parsedIndex = thisWord
  48.          parsedType.parsedIndex = "NUMBER"
  49.          foundNum = 'yes'
  50.          END
  51.       ELSE                                      /* this word is a characters */
  52.          IF foundNum = 'no' THEN DO                   /* no numbers seen yet */
  53.             parsedIndex = parsedIndex + 1
  54.             parsedValue.parsedIndex = thisWord
  55.             parsedType.parsedIndex = "STRING"
  56.             END
  57.          ELSE DO                   /* numbers previously seen; stop the scan */
  58.             parsedIndex = parsedIndex + 1
  59.             parsedValue.parsedIndex = Subword(range1.row, 1, i)
  60.             parsedType.parsedIndex = "STRING"
  61.             LEAVE                                      /* done with this row */
  62.             END
  63.       END
  64.    /* We make a special case if there are 5 cells to be set in this row, in  */
  65.    /* order to demonstrate the Set123Range external function.                */
  66.    IF parsedIndex = 5 THEN DO               /* special case: use Set123Range */
  67.       CALL Set123Range "RANGE1", 1, 4, row, parsedType.5, parsedValue.5, ,
  68.          parsedType.4, parsedValue.4, parsedType.3, parsedValue.3, ,
  69.          parsedType.2, parsedValue.2, parsedType.1, parsedValue.1
  70.       END
  71.    ELSE DO                                                 /* use Set123Cell */
  72.       j = 1
  73.       DO i = parsedIndex TO 1 BY -1                 /* loop to set the cells */
  74.          CALL Set123Cell "RANGE2", 1, j, row, parsedType.i, parsedValue.i
  75.          j = j + 1
  76.          END
  77.       END
  78.    END
  79. RETURN
  80.