home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Utilities / QuickFile / ARexx / FindReplace.quickfile < prev    next >
Text File  |  2000-05-26  |  3KB  |  133 lines

  1. /*
  2. $VER: FindReplace.quickfile 1.11 (26 May 2000  14:59:01) by M Andre Z Eckenrode
  3.  
  4. Replaces an existing (sub)string in a desiganted field in all records in the
  5. current index with a new (sub)string.
  6.  
  7. It is assumed that the search string is to be replaced with an empty string if
  8. either REPLACE is selected while the requester string gadget is empty, or
  9. CANCEL is selected, but the operation may still be cancelled via the subsequent
  10. confirmation requester.
  11.  
  12. Requires QuickFile v3.24 or higher, (rexx)reqtools.library and the following
  13. external function macros:
  14.  
  15.   FixQuotes.quickfile
  16.   ReSort.quickfile
  17.   ProgressWin.quickfile
  18.   GetViewWin.quickfile
  19.  
  20. */
  21.  
  22. options results
  23.  
  24. lib = 'rexxreqtools.library'
  25. if ~show('l',lib) then call addlib(lib,0,-30)
  26.  
  27. body = 'Select field to search...'
  28. gads = '  _Ok  |_Cancel'
  29. title = 'FindReplace.quickfile'
  30. tag = 'reqf_centertext'
  31. eztag = 'rtez_flags = ez'tag
  32. tags = eztag
  33. call notify
  34. if choice = 0 then exit
  35.  
  36. reqfield nocalc
  37. if rc = 5 then exit
  38. fld = upper(result)
  39.  
  40. lf = d2c(10)
  41. body = 'String to search for in field'lf'«'fld'»:'
  42. gads = ' _Any Case |_Match Case| _Cancel '
  43. gstag = 'rtgs_flags = gs'tag
  44. call getstring
  45. case = rtresult
  46. old = str
  47. if case = 0 then exit
  48. else if old == '' then do
  49.     body = 'No search string was entered.'
  50.     gads = '_Exit'
  51.     call notify
  52.     exit
  53. end
  54.  
  55. body = 'String to replace'lf'"'old'"'lf'with in field'lf'«'fld'»:'
  56. gads = '_Replace|_Cancel'
  57. call getstring
  58. new = str
  59.  
  60. body = 'Replacing'lf'"'old'"'lf'with'lf'"'new'"'lf'in field'lf'«'fld'».'lf'Are you sure?'
  61. gads = '_Yes| _No'
  62. tags = eztag'|ezreqf_noreturnkey'
  63. call notify
  64. if choice = 0 then exit
  65.  
  66. ndx = 'arexx/resort'(fld)
  67. parse var ndx code ' ' ndx
  68. if code > 1 then exit
  69. else if code = 1 then do
  70.     body ='All available fields to be modified.'lf'No unused field to re-sort database with.'lf'Records may be operated on inconsistently.'
  71.     gads = '_Proceed|  _Exit '
  72.     call notify
  73.     if choice = 0 then exit
  74. end
  75.  
  76. numrecs
  77. recs = result
  78. soi = -1*(recs-1)
  79. next '"'soi'"'
  80.  
  81. oldlen = length(old)
  82. newlen = length(new)
  83. ups = 0
  84. noups = 0
  85.  
  86. esc = d2c(27)
  87. line = '  Working...Record '
  88. winspec = 'arexx/progresswin'(length(line)+(2*length(recs))+4,title)
  89. call open(1win,winspec,'w')
  90. call writech(1win,esc'[0 p'lf||line)
  91.  
  92. do i = 1 to recs
  93.     call writech(1win,esc'[2;20f'i 'of' recs)
  94.     getfield '"'fld'"'
  95.     fldval = result
  96.     if case = 2 then startpos = pos(old,fldval)
  97.     else startpos = pos(upper(old),upper(fldval))
  98.     if startpos > 0 then do
  99.         fldval = insert(new,delstr(fldval,startpos,oldlen),startpos-1)
  100.         if pos('"',fldval) > 0 then fldval = 'arexx/fixquotes'(fldval)
  101.         putfield '"'fld'" "'fldval'"'
  102.         if rc > 0 then do
  103.             body = 'Unable to replace'lf'"'old'"'lf'with'lf'"'new'"'lf'in field'lf'«'fld'».'lf'Is the field type compatible?'
  104.             gads = '_Exit'
  105.             tags = eztag
  106.             call notify
  107.             exit
  108.         end
  109.         updrec
  110.         if rc = 0 then ups = ups+1
  111.         else noups = noups+1
  112.     end
  113.     next
  114. end
  115.  
  116. call close(1win)
  117. setindex '"'ndx'"'
  118.  
  119. refresh
  120. body = 'Completed!'lf||ups 'record(s) successfully updated.'lf'Update failed for' noups 'record(s).'
  121. gads = '_Done'
  122. tags = eztag
  123. call notify
  124. exit
  125.  
  126. notify:
  127.     choice = rtezrequest(body,gads,title,tags)
  128. return
  129.  
  130. getstring:
  131.     str = rtgetstring(,body,title,gads,gstag)
  132. return
  133.