4D v15.4

EXECUTE FORMULA

Home

 
4D v15.4
EXECUTE FORMULA

EXECUTE FORMULA 


 

EXECUTE FORMULA ( statement ) 
Parameter Type   Description
statement  String in Code to be executed

EXECUTE FORMULA executes statement as a line of code. The statement string must be one line. If statement is an empty string, EXECUTE FORMULA does nothing.

The rule of thumb is that if the statement can be executed as a one-line method, then it will execute properly. Use EXECUTE FORMULA sparingly, as it slows down execution speed. In a compiled database, the line of code is not compiled. This means that statement will be executed, but it will not have been checked by the compiler at compilation time.

The statement can include the following elements:

  • a Call to a project method
  • a Call to a 4D command
  • an Assignment

The formula can include process variables and interprocess variables. However, the statement cannot contain control of flow statements (If, While, etc.), because it must be in one line of code.

To ensure that the statement will be evaluated correctly regardless of the 4D language or version used, we recommend using the token syntax for elements whose name might vary between different versions (commands, tables, fields, constants). For example, to insert the Current time command, enter 'Current time:C178'. For more information about this, refer to Using tokens in formulas.

You want to add and type a dynamic column in a list box:

  //Add column
 C_POINTER($Ptr_nil)
 $Txt_column:="column"
 $Txt_header:="header"
 LISTBOX INSERT COLUMN(*;"listbox";MAXLONG;$Txt_column;$Ptr_nil;$Txt_header;$Ptr_nil)
 
  //set column type, here ARRAY OBJECT
  //ARRAY OBJECT((OBJECT Get pointer(Object named;$Txt_column))->;0)
 EXECUTE FORMULA("ARRAY OBJECT:C1221((OBJECT Get pointer:C1124(3;\""+$Txt_column+"\"))->;0)")

You want to execute formulas including calls to 4D commands and tables. Since these elements could potentially be renamed, you can ensure correct execution in future versions of your application by using the token syntax as shown here:

 EXECUTE FORMULA("Year of:C25 ([Products:5]Creation_Date:2])+$add")



See also 

Command name
EDIT FORMULA
EXECUTE METHOD
Using tokens in formulas

 
PROPERTIES 

Product: 4D
Theme: Formulas
Number: 63

 
HISTORY 

Modified: 4D v11 SQL

 
ARTICLE USAGE

4D Language Reference ( 4D v15)
4D Language Reference ( 4D v15.4)
4D Language Reference ( 4D v15.3)