home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / viscobv6.zip / vac22os2 / ibmcobol / samples / toolkit / rexx / wps / wpsorxfl.cmd < prev   
OS/2 REXX Batch file  |  1996-11-19  |  4KB  |  83 lines

  1. /******************************************************************************/
  2. /*  WPSORXFL                 Object REXX Samples                              */
  3. /*                                                                            */
  4. /*  A workplace shell example.                                                */
  5. /*                                                                            */
  6. /*  This program demonstrates a couple of useful routines for folders.        */
  7. /*  The first routine will take a WPS folder as input and return an array of  */
  8. /*  SOM objects; one for each object in that folder.                          */
  9. /*  The second routine will take an array of WPS objects and a string;        */
  10. /*  returning an array of objects that match the string.                      */
  11. /*  It also uses 3 methods to iterate over arrays (supplier, do while, and    */
  12. /*  do over) as iteration examples.                                           */ 
  13. /******************************************************************************/
  14. trace o
  15. call wpconst                                /* Wpconst is needed by the       */
  16.                                             /* GetFolderObjects routine       */
  17. desktopArray = GetFolderObjects(.wpdesktop) /* find all objects on the desktop*/
  18.  
  19. cursor = desktopArray~supplier              /* use supplier to get all objects*/
  20. do while cursor~available
  21.     say 'Title:'cursor~item~wpQueryTitle'   String:'cursor~item~string
  22.   cursor~next
  23. end
  24. say '   '
  25.                                             /* Now get just WPS folders that  */
  26.                                             /* are on the desktop             */
  27. desktopFolders = FilterByString(desktopArray, 'a WPFolder')
  28. say 'Number of folders on desktop:'desktopfolders~size
  29. cursor = desktopFolders~supplier
  30. do while cursor~available
  31.     say 'Title:'cursor~item~wpQueryTitle
  32.   cursor~next
  33. end
  34. exit
  35.  
  36. /******************************************************************************/
  37. /* This procedure will create an array of som objects that are contained in   */
  38. /* the folder passed in as the argument. wpconst is required.                 */
  39. /******************************************************************************/
  40. GetFolderObjects: procedure expose wpconst
  41. use arg fld
  42.  
  43. fldArray = .array~new
  44. num = 0
  45.  
  46. fld~wpPopulate(0, fld~wpQueryTitle, .false)
  47. first = fld~wpQueryContent(fld,.wpconst[QC_FIRST])
  48. last = fld~wpQueryContent(fld,.wpconst[QC_LAST])
  49.  
  50. this = first                                /* we start with the 1st object   */
  51. do while this \= .nil
  52.   num = num + 1
  53.   fldArray[num] = this                      /* Save object ptr in array       */
  54.   prev = this                               /* keep reference to prev object  */
  55.   if this = last then                       /* Are we at end of list?         */
  56.     this = .nil                             /* if so, indicate at end.        */
  57.   else                                      /* otherwise, get next folder item*/
  58.     this = fld~wpQueryContent(this,.wpconst[QC_NEXT])
  59.  
  60.   prev~wpUnLockObject                       /* unlock previous object.        */
  61.  
  62. end
  63. return fldArray
  64.  
  65. /******************************************************************************/
  66. /* FilterByString procedure                                                   */
  67. /* This routine takes an array and an string for input and returns a new array*/
  68. /* of the items whose "string" method output matches the input string.        */
  69. /******************************************************************************/
  70. FilterByString: procedure
  71. use arg inarray, instring
  72.  
  73. newArray = .array~new
  74. num = 0
  75. do x over inarray
  76.   if (x~string = instring) then
  77.   do
  78.     num = num + 1
  79.     newArray[num] = x
  80.   end
  81. end
  82. return newArray
  83.