Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - replace assign values to database fields http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 replace             Assign values to database fields
------------------------------------------------------------------------------
 Syntax
   [!sAlias] replace [scope] field with xExpr[, field with xExpr[,...]] ;
                     [while lExp] [for lExp]

 Arguments
   sAlias is the database to operate on.
   scope specifies a portion of the source database.
   field is a database field.
   xExpr is a value to assign to a field.
   lExp is a logical expression.

 Description
   The replace command replaces the contents of field with the results
   of xExpr and then commits the changes to the current or selected alias.

   The default scope for replace is the current record.

   If xExpr is a character expression, the number of characters replaced
   from xExpr to field depends on the length of field. The record
   pointer may not be moved during the replace, meaning any function
   within the replace expression may not seek, go, 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.

   The assignment operator := can be used as an alternative for a single
   scoped replace command, i. e. instead of

   replace field with xExpr

   the following syntax is legal:

   field := xExpr

 Example
   #define EXAMPLE_DATABASE
   #include example.hdr

   proc ChangeName
   param alias sDbf, field char( 15 ) cField, field char( 255 ) cFind, ;
      const char cReplace
   // Generic replace procedure
   !sDbf replace all cField with cReplace for cField = cFind
   endproc
   
   proc Test_replace
   vardef
      ulong nRec
   enddef
   open sTest
   ? recno(), sTest->firstname, sTest->lastname
   // replace two fields in one record
   replace sTest->firstname with "Fred", sTest->lastname with "Flintsone"
   ? recno(), sTest->firstname, sTest->lastname
   // change a spelling in a customer database
   locate for sTest->lastname = "Myers"
   nRec := recno()
   ? recno(), sTest->firstname, sTest->lastname
   replace all sTest->lastname with "Meyers" for sTest->lastname = "Myers"
   go nRec
   ? recno(), sTest->firstname, sTest->lastname
   nRec := recno()
   ChangeName( sTest, sTest->firstname, sTest->firstname, "Mickey" )
   go nRec
   ? recno(), sTest->firstname, sTest->lastname
   endproc

   proc main
   Test_replace()
   endproc

See Also: := Database command scope table

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson