Wednesday, September 29, 2010

Cruising the Calculate tab

Like its Format and Validate tab brethren, options on the Calculate tab apply only to Combo box and Text field types. You use these commands to perform mathematical calculations on data entered in two or more form fields and display the result in another field. This feature is often used in an interactive order form where the product of an item’s quantity and price is automatically displayed in a total field. In addition, it’s possible to perform more advanced calculations using JavaScript.
To define the fields in a form that will perform calculations or attach a JavaScript calculation to a field, select one of the three radio buttons on the Calculate tab:
  • Value Is Not Calculated: The default state. Select this option if you don’t want to perform a calculation on data entered in a field.
  • Value Is the of the Following Fields: Provides a drop-down list of five operations: sum (+), product (), average, minimum, and maximum. Select an operation option and then click the Pick button to open the Field Selection dialog box, which displays a list of fields in your form. Select a field’s check box in the Select Fields for Calculation list box. You can select more than one field at a time, and you can select or deselect all the fields by clicking the appropriate button. When you’re finished selecting fields, click the OK button.
  • Custom Calculation Script: Click the Edit button to open the JavaScript Edit window. If you’re familiar with JavaScript language, you can write your own or copy and paste a predefined JavaScript in the script editing window. Click OK to close the JavaScript Edit window. The calculation script appears in a preview box below the Custom Calculation Script radio button. Note that you can use the arrow keys to view the script, but you can’t edit it.
By default, field calculations are performed in the same order as the form field’s tab order — that is, the order in which the fields are selected when the user presses the Tab key. This is not always a good idea, especially if your form contains multiple calculations where the result of one calculation depends on the result of another calculation. To override the default, set your own calculation order by choosing Advanced➪Forms➪Set Field Calculation Order to open the Calculated Fields dialog box. Select fields in the window and use the Up and Down buttons to arrange their calculation order, and then click OK to save your changes.

Viewing the Validate tab

Like the Format and Calculate tabs, options on the Validate tab apply only to Combo box and Text field types. You use these commands to restrict data entry in a field to a specific range, such as a dollar amount less than or equal to $1,000. Note that in order to specify a data range, the selected form field must be formatted with either the Number or Percentage category on the Formatting tab of the field type Properties dialog box.
You can accomplish more sophisticated validation, such as restricting data to specific values and characters, through the use of JavaScript. You might, for example, want to limit a date entry to only the years between 1950 and 2000 or allow a password that only contains three letters and four numbers separated by a dash.
To set a data range or attach a JavaScript to validate a field, click one of the radio buttons on the Validate tab:
  • Field Value Is Not Validated: The default state. This radio button is selected automatically if a field does not use number or percentage formats (selected on the Format tab). Otherwise, click this option if you don’t want validation applied to data entered in a field.
  • Field Value Is In Range: Provides two text boxes in which to define upper- and lower-range parameters. Type a number in the From or To field to specify limits on a data range.
  • Run Custom Validation Script: Click the Edit button to open the JavaScript Edit window. If you’re familiar with JavaScript language, you can write your own or copy and paste a predefined JavaScript in the script editing window. Click OK to close the JavaScript Edit window. The validation script appears in a preview box below the Run Custom Validation Script radio button. Note that you can use the arrow keys to view the script, but you can’t edit it.

Getting familiar with the Format tab


The commands on the Format tab are applicable only to Combo Box and Text field types. The same can be said of the Validate and Calculate tabs as well. These format options enable you to specify a particular numerical format for data entered in the form field. For example, you can create a text field for entering a Social Security number that must contain nine numbers and automatically places dashes after the third and fifth numbers.
The Format tab presents a list of format categories in the Select Format Category list box. Clicking a category displays specific options for that category in the Options area below the drop-down list. Choose formatting options and click OK to apply that formatting to your form field. The following list describes the categories and options provided on the Format tab:
  • None: The default setting that specifies that no formatting is applied to data entered in a field.
  • Number: Type a number in the Decimal Places field or click the attached spinner buttons to set the number of decimal places for the number entered in the text field. Use the Separator Style drop-down list to select a comma and decimal separators preference. Use the Currency Symbol drop-down list to select from a wide variety of foreign currency symbols. Select how negative numbers appear in a field by selecting the Show Parentheses or Use Red Text check box. (If neither check box is selected, negative numbers appear with a minus sign before the number.)
  • Percentage: Automatically displays the percent symbol with numbers entered in a Text or Combo Box type field. Type a number in the Decimal Places field or click the attached spinner buttons to set the number of decimal places. Click the arrow on the Separator to select a comma and decimal separators preference. The sample area provides a preview of your selected percentage options.
  • Date: Choose from a wide variety of date-only or date and time formats (choose the Time category for time-only formats) in the Date Options list box. The sample area below the Date options list box displays the format style of a selected formatting code. For example, selecting the formatting code m/d/yy in the Date Options list displays its format style as 4/19/03. When you’re familiar with these simple date and time formatting codes, you can select Custom at the bottom of the Date Options list box and create custom date and time formats in the text box provided.
  • Time: Choose from four time formats provided in the Time Options list or choose Custom to create your own. View the time format style for the selected time formatting code in the sample area below the list box.
  • Special: Choose from the list of five options that appear in the Special Options list: Zip Code, Zip Code+4, Phone Number, Social Security Number, or Arbitrary Mask, which is used to specify the types of characters a user can enter in any given position and how the data displays in a text field.
  • Custom: Provides a means of using JavaScript to format text or apply keystroke validation to text entered in a field. (See the next section to find out about field validation.) Click the Edit button next to either the Custom Format Script or Custom Keystroke Script area to open the JavaScript Edit window. If you’re familiar with JavaScript language, you can write your own or copy and paste a predefined JavaScript in the script editing window. Click OK to close the JavaScript Edit window. The keystroke or formatting script appears in its proper Custom Options area. Note that you can use the arrow keys to view the script, but you can’t edit it.