home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 13
/
AACD13.ISO
/
AACD
/
Utilities
/
QuickFile
/
ARexx
/
FindReplace.quickfile
< prev
next >
Wrap
Text File
|
2000-05-26
|
3KB
|
133 lines
/*
$VER: FindReplace.quickfile 1.11 (26 May 2000 14:59:01) by M Andre Z Eckenrode
Replaces an existing (sub)string in a desiganted field in all records in the
current index with a new (sub)string.
It is assumed that the search string is to be replaced with an empty string if
either REPLACE is selected while the requester string gadget is empty, or
CANCEL is selected, but the operation may still be cancelled via the subsequent
confirmation requester.
Requires QuickFile v3.24 or higher, (rexx)reqtools.library and the following
external function macros:
FixQuotes.quickfile
ReSort.quickfile
ProgressWin.quickfile
GetViewWin.quickfile
*/
options results
lib = 'rexxreqtools.library'
if ~show('l',lib) then call addlib(lib,0,-30)
body = 'Select field to search...'
gads = ' _Ok |_Cancel'
title = 'FindReplace.quickfile'
tag = 'reqf_centertext'
eztag = 'rtez_flags = ez'tag
tags = eztag
call notify
if choice = 0 then exit
reqfield nocalc
if rc = 5 then exit
fld = upper(result)
lf = d2c(10)
body = 'String to search for in field'lf'«'fld'»:'
gads = ' _Any Case |_Match Case| _Cancel '
gstag = 'rtgs_flags = gs'tag
call getstring
case = rtresult
old = str
if case = 0 then exit
else if old == '' then do
body = 'No search string was entered.'
gads = '_Exit'
call notify
exit
end
body = 'String to replace'lf'"'old'"'lf'with in field'lf'«'fld'»:'
gads = '_Replace|_Cancel'
call getstring
new = str
body = 'Replacing'lf'"'old'"'lf'with'lf'"'new'"'lf'in field'lf'«'fld'».'lf'Are you sure?'
gads = '_Yes| _No'
tags = eztag'|ezreqf_noreturnkey'
call notify
if choice = 0 then exit
ndx = 'arexx/resort'(fld)
parse var ndx code ' ' ndx
if code > 1 then exit
else if code = 1 then do
body ='All available fields to be modified.'lf'No unused field to re-sort database with.'lf'Records may be operated on inconsistently.'
gads = '_Proceed| _Exit '
call notify
if choice = 0 then exit
end
numrecs
recs = result
soi = -1*(recs-1)
next '"'soi'"'
oldlen = length(old)
newlen = length(new)
ups = 0
noups = 0
esc = d2c(27)
line = ' Working...Record '
winspec = 'arexx/progresswin'(length(line)+(2*length(recs))+4,title)
call open(1win,winspec,'w')
call writech(1win,esc'[0 p'lf||line)
do i = 1 to recs
call writech(1win,esc'[2;20f'i 'of' recs)
getfield '"'fld'"'
fldval = result
if case = 2 then startpos = pos(old,fldval)
else startpos = pos(upper(old),upper(fldval))
if startpos > 0 then do
fldval = insert(new,delstr(fldval,startpos,oldlen),startpos-1)
if pos('"',fldval) > 0 then fldval = 'arexx/fixquotes'(fldval)
putfield '"'fld'" "'fldval'"'
if rc > 0 then do
body = 'Unable to replace'lf'"'old'"'lf'with'lf'"'new'"'lf'in field'lf'«'fld'».'lf'Is the field type compatible?'
gads = '_Exit'
tags = eztag
call notify
exit
end
updrec
if rc = 0 then ups = ups+1
else noups = noups+1
end
next
end
call close(1win)
setindex '"'ndx'"'
refresh
body = 'Completed!'lf||ups 'record(s) successfully updated.'lf'Update failed for' noups 'record(s).'
gads = '_Done'
tags = eztag
call notify
exit
notify:
choice = rtezrequest(body,gads,title,tags)
return
getstring:
str = rtgetstring(,body,title,gads,gstag)
return