This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v20
WP INSERT FORMULA

WP INSERT FORMULA 


 

WP INSERT FORMULA ( targetObj ; formula ; mode {; rangeUpdate} )  
Parameter Type   Description
targetObj  Object in Range or element or 4D Write Pro document
formula  Object in Formula object
mode  Number in Insertion mode
rangeUpdate  Number in Includes or excludes the inserted content within the range

The WP INSERT FORMULA command inserts a formula in targetObj according to the specified insertion mode.

In the targetObj parameter, you can pass:

  • a range, or
  • an element (table / row / cell(s) / paragraph / body / header / footer / section / subsection / inline picture), or
  • a 4D Write Pro document.

In the formula parameter, pass the 4D formula to evaluate in an object created by the Formula or Formula from string command. 

In the mode parameter, pass one of the following constants to indicate the insertion mode to be used:

Constant Type Value Comment
wk append Longint 2 Insert contents at end of target
wk prepend Longint 1 Insert contents at beginning of target
wk replace Longint 0 Replace target contents
  • If targetObj is a range, you can use the optional rangeUpdate parameter to pass one of the following constants to specify whether or not the inserted formula is included in the resulting range: 
     
    Constant Type Value Comment
    wk exclude from range Longint 1 Inserted contents not included in updated range
    wk include in range Longint 0 Inserted contents included in updated range (default)

    If you do not pass a rangeUpdate parameter, by default the inserted formula is included in the resulting range. 
     
  • If targetObj is not a range, rangeUpdate is ignored.

Note: Keep in mind that, when called, the formula object is evaluated within the context of the database or component that created it.

Example  

To replace all current date formulas with formatted strings:

 

 C_COLLECTION($_formulas)
 C_OBJECT($find;$newFormula)
 
  // define the formula to find
 $find:=Formula(Current date)
 
  // define the replacement formula
 $newFormula:=Formula(String(Current date;System date long))
 
  // find all formulas in the document
 $_formulas:=WP Get formulas(WriteProArea)
 
  // query the collection from WP Get formulas
 $_formulas:=$_formulas.query("formula.source =:1";$find.source)
 
  // then replace each formula
 For each($formula;$_formulas)
    WP INSERT FORMULA($formula.range;$newFormula;wk replace)
 End for each



See also 

Managing formulas
WP COMPUTE FORMULAS
WP FREEZE FORMULAS
WP Get formulas

 
PROPERTIES 

Product: 4D
Theme: 4D Write Pro Language
Number: 1703

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v18 R2

 
ARTICLE USAGE

4D Write Pro Reference ( 4D v20)