The execute( function allows a formula to execute a sequence of statements and return a result.
Parameters
This function has two parameters:program – is the text (source code) of the program you want to run.
parameters – is a list of parameters to be passed to the subroutine. This list is optional, you don’t have to pass any parameters if you don’t need to. See parameter( and setparameter for more information on accessing parameters within a subroutine.
Description
This statement allows a formula to build a “mini-procedure” on the fly, and then run that procedure as a subroutine to calculate the value of the function. The text of the “mini-procedure” can be in a field, a variable, or constructed using a combination of fields, variables and operators. At some point the mini-procedure must contain a functionvalue statement that tells Panorama what value to return from the function. (The procedure may contain multiple functionvalue statements, in which case the function will return the value of the last functionvalue statement executed.)
This example checks to see if a Text Editor SuperObject is currently active, and if so, returns the currently selected text in that object.
execute(|||
if info("activesuperobject")="" // is there any object being edited?
functionvalue "" // no, return nothing
rtn
endif
local theSelectedText
activesuperobject "GetSelectedText",theSelectedText
functionvalue theSelectedText
|||)
Normally there is no way to obtain this selected text in a formula, but using the execute( function you can do so easily and use that text in further calculations.
The execute( function (and call( function) allow you to perform procedure statements anywhere a formula is allowed, including in form objects, formulafill, etc. However, you should keep in mind that using a procedure within a formula can drastically slow down the operation of the formula. You should also avoid statements that change window state or pause for user interaction (for example message, gettext, window, openfile, etc.).
The execute( function allows you to supply one or more parameters to be passed to the subroutine (each parameter must be separated by a comma). When using the execute formula the parameters are listed after the source code, like this:
execute(source,parameter1,parameter2,parameter3, ... parameterN)
Within the source code you can access the parameters with the parameter( function, or change the value of a parameter with the setparameter statement. This example first defines two mini-procedures, then uses them to calculate a border around a group of objects. Each object is identified by its name.
local getObjectRectangle,unionRectangles,addressBorderRectangle
getObjectRectangle=|||
object parameter(1)
functionresult objectinfo("rectangle")
|||
unionRectangles=|||
local urect
urect=parameter(1)
for i,2,info("parameters")
urect=unionrectangle(urect,parameter(i)
endloop
functionresult urect
|||
addressBorderRectangle=execute("unionRectangles",
execute("getObjectRectangle","Address"),
execute("getObjectRectangle","City"),
execute("getObjectRectangle","State"),
execute("getObjectRectangle","Zip"),
execute("getObjectRectangle","Country"))
You can also use the setparameter statement to modify the value of a parameter passed to the mini-procedure.
If there is a syntax error in the mini-program (misspelled command, unexpected formula operator, etc.) the function will return an error message describing the problem instead of the calculated value (since there is a syntax error, it cannot even try to run the program.
If there is a run-time error in the mini-program (for example a missing variable, incorrect data type, etc.) the function will also return an error message describing the problem. Or you can also use the if error, try/catch or onerror statements (see Error Handling) to trap the error yourself and take appropriate action without returning an error. You can even combine the functionvalue statement with the error( function to return your own custom error message.
Error Messages
Execute( code contains syntax error: – This error message indicates that there is a misspelled command, unexpected formula component, or other syntax error in the supplied mini-program.
Execute( code does not return a value (you must add the functionvalue statement). – The mini-program must include a functionvalue statement. If there is a functionvalue statement and you still see this error, the functionvalue is not being executed – check the logic of the mini-program.
See Also
History
Version | Status | Notes |
10.0 | New | New in this version. |