Expression Creator Dialog

Top  Previous  Next


The Expression Creator dialog is used in many places for entering expressions.  It's invoked for "Add Expression" functions in queries, scripts, etc., and also available anywhere expressions can be edited.


In places where a dialog contains an expression editing field already, or shows an expression as static text, a button like "Test/Edit Expression" will open the Expression Creator dialog.  Besides just a window for editing the expression, this has a few special functions to assist in creating the expression.


The Expression window acts like most other text entry windows, except that it also does some basic syntax highlighting. This colors the text according to the type of expression element.  This happens dynamically as you type, as soon as the expression can be parsed into recognizable elements.  The meaning of the colors is as follows:


 Black -- Basic elements like math operators, variables and commas

 Green -- Boolean operators (AND, OR, NOT)

 Dark blue -- Numeric values

 Violet -- Boolean values (.T. and .F.)

 Dark Red -- Date values (eg. {1/5/2006} )

 Bright blue -- Recognized function names, once the parenthesis is present, like : Upper(

 Magenta -- Text values

 Bright Red -- Mismatched parenthesis, braces or quotes (can't find the matching one)


You can type and edit the expression manually, or you can also use the Insert Expression Element button to select functions and operators to be pasted into the expression.  This will open the Expression Elements dialog (explained below).  If you have anything highlighted in the Expression window, the highlighted text will be replaced with the element selected (a prompt will warn you that this will happen).


One you have an expression entered, you can test it to a certain extent by clicking the Calculate button.  (For that matter, you can use it as a fancy calculator this way).  It will parse and execute the expression if possible.  If there are no errors, the resulting value for the expression will be shown in the Result window.  If there are errors, an Errors window will be added to the bottom and will list all errors encountered.  If there are many errors, you can scroll to see the rest.  (Often times one typing mistake will result in many errors as it continues to try to parse the whole expression.)  Note that if the result is a record, the Record ID of the record will be shown (like "#000000002").


You can edit the expression and use Calculate as many times as you like.  Once you're satisfied, click Save and the entire expression will be saved into whatever function you were editing the expression for.


Note that the Calculate function won't necessarily have all of the context information needed or variables defined to successfully execute the expression.  If a base table is known, then it will use the first record in that table (e.g. the first reservation) as the operating record.  Otherwise, most context information will not be valid for executing the expression here, which may result in errors even if the expression will work fine in its proper context.  



Expression Timing


When you use Calculate, it will show the approximate time it takes to parse and execute the expression.  If you're programming a complex report, this may help you make it more efficient by modifying the expression to execute more quickly.  


Timing Tip: Most expressions take too little time to measure accurately just one time through.  To get a better idea of the execution time, use the EvalQRepeatWhile function to make it repeat 100 or 1000 times.  Note that the EvalQRepeatWhile function takes a quoted boolean argument and a count, so you need to modify the expression to be boolean (and always return True).  One way to do this is to repeat the expression twice, once on each side of =, and use half the count.  For instance, to measure the execution time of the expression Upper('abc') 1000 times, enter it like this (using a repeat count of 500 since the Upper() function is repeated twice in the expression):


 EvalQRepeatWhile( "Upper('abc') = Upper('abc')", 500)


Note that with the EvalQRepeatWhile function, the expression in quotes is only Parsed once.  Only the Execute portion of the processing is done multiple times.  For places like queries where speed is important, execution is the time that's most important anyway.




Additional Topics:


Expressions Overview

Expression Syntax

Expression Context

Expression Processing


Expression Elements


Function Reference


Macro Expressions




Color Schemes






Advanced Customizations Overview & other topics



Page URL

Campground Master Home