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

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