home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Du Jour
/
SoftwareDuJour.iso
/
BUSINESS
/
DBASE
/
DBREP.ARC
/
REP.PRG
< prev
next >
Wrap
Text File
|
1985-10-31
|
5KB
|
152 lines
* REP.PRG GLOBAL SEARCH AND REPLACE SUBSTRING IN FIELD
SET TALK OFF
DO WHILE .T.
ACCEPT "FIELD TO SEARCH: " TO MFIELD
IF LEN("&MFIELD") = 0
RETURN
ENDIF
STORE 'Y' TO MREPEAT,MVERIFY
* PER FIELD LOOP
DO WHILE MREPEAT = 'Y'
MCOUNT = 0
ACCEPT 'REPLACE WHAT: ' TO MTEXT
LMTEXT = LEN(MTEXT)
* CHECK FOR RESTRICTIONS TO SEARCH STRING
IF LMTEXT = 0
EXIT
ENDIF
IF '"'$MTEXT .AND. "'"$MTEXT
? "Unable to search for character strings containing both single and double quotes."
WAIT 'Please press <RETURN>. '
LOOP
ENDIF
ACCEPT 'REPLACE WITH: ' TO NTEXT
LNTEXT = LEN(NTEXT)
CLEAR
? 'FIELD: ',MFIELD
? 'REPLACE: ',MTEXT,' WITH ',NTEXT
@ 03,00 SAY '----------------------------------------'
@ 03,40 SAY '----------------------------------------'
@ 04,00 SAY '(Searching . . . )'
* LOCATE NEXT OCCURRENCE OF SUBSTRING (FROM PRESENT RECORD)
IF '"'$&MFIELD
LOCATE NEXT 50000 FOR '&MTEXT'$&MFIELD
ELSE
LOCATE NEXT 50000 FOR "&MTEXT"$&MFIELD
ENDIF
* REPLACEMENT LOOP
DO WHILE .T.
IF EOF()
GO TOP
EXIT
ENDIF
* CONDITION FOR VERIFIED REPLACEMENT
IF MVERIFY = 'Y'
@ 04,00 SAY 'RECORD: '
@ 04,08 SAY RECNO()
@ 05,00 SAY '&MFIELD: ' GET &MFIELD
* DISPLAY REPLACEMENT OPTIONS
@ 18,00 SAY '----------------------------------------'
@ 18,40 SAY '----------------------------------------'
@ 19,0 SAY 'Replace - R Continue - C Edit - E Quit - <RETURN>'
@ 20,0 SAY 'Replace all (unverified) - X Replace w/ other text - O'
* CHECK IF REPLACEMENT WILL CAUSE TEXT TO EXCEED FIELD LENGTH
IF LNTEXT > LMTEXT
LTEXT1 = LEN(&MFIELD)
LTEXT2 = LEN(TRIM(&MFIELD))
IF (LNTEXT - LMTEXT) > (LTEXT1 - LTEXT2)
* (i.e., NET INCREASE OF SUBSTRING > REMAINING SPACES IN FIELD)
MLOSS = (LNTEXT - LMTEXT) - (LTEXT1 - LTEXT2)
NLOSS = SUBSTR(STR(MLOSS),8,3)
? 'WARNING - LAST',NLOSS,'CHARACTERS WILL BE LOST.'
ENDIF
ENDIF
* ACCEPT SELECTION AND DO APPLICABLE CASE
WAIT 'ENTER YOUR SELECTION HERE: ' TO MREPLACE
MREPLACE = UPPER('&MREPLACE')
IF LEN(MREPLACE) = 0
EXIT
ENDIF
DO CASE
CASE MREPLACE = 'R'
DO REPSUB
@ 05,00 CLEAR
@ 05,00 SAY '&MFIELD: ' GET &MFIELD
@ 18,00 SAY '----------------------------------------'
@ 18,40 SAY '----------------------------------------'
@ 20,00 SAY 'ITEM REPLACED.'
WAIT 'Find next one? (Y/N) ' TO MNEXT
DO CASE
CASE UPPER("&MNEXT") = 'N'
EXIT
CASE LEN("&MNEXT") = 0
RETURN
OTHERWISE
* CONTINUE
ENDCASE
CASE MREPLACE = 'C'
* CONTINUE
CASE MREPLACE = 'E'
READ
WAIT
CASE MREPLACE = 'X'
DO REPSUB
MVERIFY = 'N'
CASE MREPLACE = 'O'
NTEXTBAK = NTEXT
ACCEPT 'Replace with: ' TO NTEXT
DO REPSUB
NTEXT = NTEXTBAK
@ 05,00 CLEAR
@ 05,00 SAY '&MFIELD: ' GET &MFIELD
@ 18,00 SAY '----------------------------------------'
@ 18,40 SAY '----------------------------------------'
@ 20,00 SAY 'ITEM REPLACED.'
WAIT 'Find next one? (Y/N) ' TO MNEXT
DO CASE
CASE UPPER("&MNEXT") = 'N'
EXIT
CASE LEN("&MNEXT") = 0
RETURN
OTHERWISE
* CONTINUE
ENDCASE
OTHERWISE
WAIT "INVALID SELECTION. TYPE ANY KEY TO TRY AGAIN. "
@ 21,00 CLEAR
LOOP
ENDCASE * Replacement/edit options
ELSE
* CONDITION FOR UNVERIFIED REPLACEMENT
@ 04,00 CLEAR
@ 04,00 SAY '(Replacing ) '
MRECORD = substr(str(RECNO()),6,5)
@ 04,12 SAY MRECORD
DO REPSUB
ENDIF * VERIFIED/UNVERIFIED REPLACEMENT
* LOCATE NEXT OCCURRENCE OF STRING
@ 04,00 CLEAR
@ 04,00 SAY '(Searching . . . ) '
* CHECK IF MTEXT IS A SUBSTRING OF NTEXT
* (IF NOT, SEARCH SAME RECORD FOR ANOTHER OCCURRENCE OF MTEXT.)
IF .NOT. MTEXT$NTEXT .AND. MREPLACE <> 'C' .AND. .NOT. BOF()
SKIP -1
ENDIF
CONTINUE
ENDDO *** REPLACEMENT LOOP (DO WHILE .T.)
? 'NUMBER OF REPLACEMENTS:',MCOUNT
?
WAIT 'ANOTHER CHANGE, SAME FIELD? (Y/N) ' TO MREPEAT
MREPEAT = UPPER('&MREPEAT')
DO CASE
CASE MREPEAT = 'Y'
MVERIFY = 'Y'
@ 02,00 CLEAR
CASE MREPEAT = 'N'
EXIT
OTHERWISE
RETURN
ENDCASE
ENDDO ** FIELD LOOP
ENDDO