Please enable JavaScript to view this site.

R:BASE 11 Beginners Tutorial

Navigation: Lesson 4 - Data Entry Forms

Using Expressions and Variables

Scroll Prev Top Next More

We first used expressions in Lesson Two when we created the computed column TotalCharge. Remember, an expression is a calculation used to determine a value. In Lesson Two, the column TotalCharge was assigned the expression: (Letters * Price).

 

An expression can also be assigned to a variable. A variable is a name you create that will contain the answer to an expression. For example, in the expression vQuantity = (12 * 10), the variable vQuantity contains the value 120.

 

You can assign a variable to an expression and then place the variable on the form. When the form is used, it will display the value of the variable.

 

In FlightForm we include a field labeled "Total Charge" that shows the total amount of money the customer is charged for the flight. To display this amount, we assign a variable to an expression that makes the same calculation that R:BASE performs for the computed column TotalCharge.

 

The reason we are using an expression in the form to do the same calculation that R:BASE performs in the table is a matter of timing: R:BASE only performs the calculation for the computed column TotalCharge when the data is stored in the table. Since we want to see the result in the form before R:BASE stores the data, we will perform the same calculation in the form.

 

To define an expression in the form:

 

1.In the "Form Designer" window, choose Variables: Add/Edit Variables...

 

The "Expression Builder" dialog box is displayed.

 

2.Enter "vTotalCharge" in "Name:"
3.Choose "CURRENCY" from the "Type:" drop down box.
4.Enter "(Letters * Price)" in the "Expression:" panel.

 

The green book button across the bottom may also be used to launch the Data Dictionary, where the column names may be captured to the Windows clipboard and placed into the field. The Data Dictionary is a utility that displays, and allows users to capture, information about the current R:BASE environment and/or connected database. In the Data Dictionary select the "Columns" tab, make sure "Tables" are listed in the drop-down, and select the Flights table. The Letters and Price columns may both be selected while holding down the [Ctrl] key. Then, press OK. If the cursor focus was not within the Expression field, click in the filed, and press [Ctrl+V]. The Data Dictionary selection will be placed into an area where input is accepted. The selected column names are separated by a comma, where the text can now be modified to match what is the expected expression value detailed in Step 4.

 

Spaces on either side of the operator are optional.

 

5.Click the Add button.

 

The variable is added and the expression is displayed in "Variables".

 

ExpressionBuilder1

 

 

Note: If you get an error message when you click the Add button, correct the expression by editing it. After editing the expression, click the Add button.

 

6.Click the "Apply" button, then"Close".

 

To look at the expression you just defined:

 

1.In the "Form Designer" window, choose Variables: List of Expressions.

 

R:BASE displays the expressions associated with the form. The expressions are listed table by table. R:BASE has assigned a number, 1, and data type, CURRENCY, to the variable you defined.

 

2.Select the "X" to return to the "Form Designer" window.