[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
##############################################################################
###+---------+################################################################
#+-| REPLACE |----------------------------------------------------------+#####
#| +---------+ The REPLACE command replaces the contents of <Field-var> |#####
#| with the results of <?-exp> and then commits the changes |#####
#| to the current or selected alias |#####
#+----------------------------------------------------------------------+#####
##############################################################################
##############################################################################
#+--| Syntax |-------------------------------------------------+##############
#| [!<Alias>] REPLACE [Scope] <Field-var> WITH <?-exp> |##############
#| [,<Field-var> WITH <?-exp>[,...]] [WHILE <L-exp>] |##############
#| [ FOR <L-exp> ] |##############
#+-------------------------------------------------------------+##############
##############################################################################
##############################################################################
######+---| Description |----------------------------------------------+######
######| The default scope for REPLACE is RECORD recno(). |######
######| -------------------------------------------------------------- |######
######| If <?-exp> is a character expression, the number of characters |######
######| replaced from <?-exp> to <Field-var> depends on the length of |######
######| <Field-var>. The record pointer may not be moved during the |######
######| replace, meaning any function within the REPLACE expression |######
######| may not SEEK, GOTO, etc. |######
######| -------------------------------------------------------------- |######
######| If the REPLACE command appears within a VALID function for a |######
######| GET, the runtime library issues a runtime error, because the |######
######| field has been suspended by the GET. |######
######+----------------------------------------------------------------+######
##############################################################################
##############################################################################
#########+--| Example 1 |-------------------------------------------+#########
#########| * REPLACE two fields in one record. |#########
#########| |#########
#########| REPLACE tv->set WITH 'RCA', tv->cost WITH ; |#########
#########| cost("RCA","Dealer") |#########
#########+----------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 2 |-------------------------------------------+#########
#########| * Change a spelling in a customer database. |#########
#########| |#########
#########| REPLACE ALL cust->name WITH 'Rian' ; |#########
#########| FOR cust->name = 'Ryan' |#########
#########+----------------------------------------------------------+#########
##############################################################################
##############################################################################
#########+--| Example 3 |-------------------------------------------+#########
#########| * A "generic" replace procedure. |#########
#########| |#########
#########| DBFDEF a |#########
#########| CHAR(20) name |#########
#########| ENDDEF |#########
#########| |#########
#########| DEFDEF b |#########
#########| CHAR(20) name |#########
#########| ENDDEF |#########
#########| |#########
#########| PROCEDURE change_name |#########
#########| PARAMETER ALIAS ndbf, FIELD CHAR(20) z, CONST CHAR ; |#########
#########| findchar, CONST CHAR replchar |#########
#########| |#########
#########| !ndbf REPLACE ALL z WITH replchar FOR z = findchar |#########
#########| ENDPRO |#########
#########| |#########
#########| {...} |#########
#########| change_name( a,a->name,"BOBBY","Bob") |#########
#########| change_name( b,b->name,"BOBBY","Bob") |#########
#########+----------------------------------------------------------+#########
##############################################################################
See Also:
FLUSH
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson