Program: Superbase 4 Version: 1.3x Topic: Setting up a form with a calculated default value Date: 10/13/92 Summary: This technote explains how to set up a form that shows a calculated default value that appears when the cursor first enters the field. This value can be modified and written to a field. This process is separated into the following steps: setting up the data file, initially setting up the form, and calculating the value. Application: In an order form, the default value for Extended Price would be Price * Units. However, this value may be changed due to special discounts, negotiations, etc. When data is being entered, the user sees the default value after he enters the Price and Units, before the cursor moves past the Extended Price field. He can then change this value, and it is stored in the Extended Price field. Once a value has been entered into this field, it won't be recalculated. Setting up the data file Create an Orders file that contains the following fields: Orderno, Price, Units, ExtPrice. 1. Run Superbase, and select File, New to create a new file. 2. Orderno may be a text or numeric field. 3. Add Price, Units, and ExtPrice as numeric fields. Do not make them calculated. Setting up the form Create a form. 1. Run the Form Designer, and use File, New to create a form. 2. Use File, SB File Open to open the orders file. 3. Use the FLD tool and place the Orderno, Price, Units, and ExtPrice fields on the form. Calculating the value Use the CLC tool to define the calculation for ExtPrice. 1. Select the CLC tool with your left mouse button. 2. Put the CLC between Units and ExtPrice. 3. Give the CLC a name -- it should be a numeric variable, like ltot%. 4. For the calculation formula, enter: LET ExtPrice.orders = (ExtPrice.orders = 0) ? Price.orders * Units.orders : ExtPrice.orders If ExtPrice has a value entered previously, it will appear. Otherwise, the result of Price * Units will appear in the ExtPrice field. 5. You can change the background and foreground color of the CLC so it is hidden on the form.