cfl_ch_3-formulas_and_functions provides a means for creating temporary cfl_ch_5-variableswhich can greatly simplify coding and debugging. This page explains how to create and use these variables. See Also

how_to_use_declare_and_case_statements_to_simplify_layouts

Basic Discussion of Approach

We use Declare statements to make the code easier to read and follow. Instead of embedding long strings of “If/then” statements or other complicated formulas in one long formula, we break them up using easily understood labels for what each set of code (Object) is doing.

cfl_ch_3-formulas_and_functions pulls all the code for a Product into one large formula. We have found that Declare variables, while temporary, should not be duplicated in the formulas used in a product; so we make each one unique to the variable or form it is being used with.

  1. Open the CFL formula builder where you are creating code: The format is “Declare” followed by the name of the temporary variable. If you inadvertently select a name already in use by a variable, the color will change to blue. Similarly if you select a name which has been used for a Constant, the color will also change to a maroon. If you are going to use your variables in a formula, you can do so but must “Declare” them before the formula. The name is followed by the := (colon + equal sign) after which you enter the formula you want. You terminate the code with a semi-colon for all lines. The last line/set of code in cfl_ch_3-formulas_and_functions should not have the semi-colon termination. Unlike some other code conventions you do not need to indicate the type of variable you are creating – IE string, number, “Yes/No” (Boolean); but when creating “Yes/No” variables, we set the code up so the type is obvious – E.G. Declare VariableHasAValue := IF MaterialType _ckgedit_QUOTckgedit> Then TRUE Else FALSE Endif; You can then use the code in your formula like any other Boolean variable. Using the example code here and combining that with the code below, you could have a formula like – If VariableHasAValue Then SalePrice * ProductMarkup * Quantity Else 0 Endif. - Create a temporary variable for the Markup % Declare ProductMarkup := IF ProductMarkup > 0 THEN 1/( (100-ProductMarkup)/100) ELSE 1 ENDIF ; Create temporary variable for the cost of a single unit List Price Value returns cost per square foot Declare SalePrice := ListPriceValue(UnitPriceList)* Area In SqFeet; Return the Total Price SalePrice * ProductMarkup * Quantity

Contributor: Steve Gillispie, Acorn Sign Graphics

Date: 2/20/2011

Version: Control 04.50.1102.0401

You could leave a comment if you were logged in.