======================================================================
     FORMATTING IN FORMS
     ======================================================================
     PRODUCT:  R:BASE             VERSION :  4.0
     AREA   :  FORMS              CATEGORY:  VIEWS          DOCUMENT#:  653
     ======================================================================
 
 
     In R:BASE 4.0 you can use the new format masks, the FORMAT function, 
     and the FLOAT and INT functions to solve the annoying display problems 
     associated with entry forms.
 
     Format Masks
     ============
     Format masks work on text fields only. They allow you to specify 
     characters such as dashes that are automatically placed in position 
     in the field and to require entry of only specific characters such 
     as numbers.
 
     To assign a format mask, choose Field settings for the field requiring 
     the format mask and answer YES to the question "Do you want a default 
     value or a format mask?" Then enter the desired format mask, which must 
     start and end with a square bracket as shown below:
 
       <> [999-99-9999] automatically inserts dashes in Social Security 
          numbers.
       
       <> [(999)999-9999] separates an area code from a telephone number 
          with parentheses.
       
       <> [99999] specifies that only numbers can be entered. When you use 
          this format mask, particularly handy for ZIP code fields, you 
          must include the entire field length within the brackets. R:BASE 
          does not allow entry of anything other than numbers. No error 
          message is displayed if the user tries to enter other characters, 
          but nothing is placed in the field.
       
       <> [________] or [%%%%%%%%] for the length of the text field ensures 
          that all letters in the field are uppercase.
       
       <> [||||||||] or [????????] for the length of the text field ensures 
          that all letters in the field are lowercase.
       
       <> [_|||||||] or [%???????] for the length of the text field ensures 
          that the first letter in the field is capitalized.
 
       <> For long text fields you might want to define an expression using 
          one of the Supermath functions LUC, ULC, ICAP1, ICAP2 to do all 
          uppercase, all lowercase, or capitalization. 
 
     Formatting Non-text Fields
     ==========================
     Even though you can specify a format mask only on a text field, you can 
     make it appear to the user as if you are formatting currency, double, 
     or integer data. To use with non-text data types, define expressions in 
     the form to convert the non-text data to text and then back to its 
     original data type.
 
     Specify the Number of Decimal Places 
     ====================================
     Add these two expressions in this order to your form to convert the real 
     or double column to text and back:
 
        
        
        
        colname = (FLOAT(.varname))
        varname = (CTXT(colname))
 
     The variable is located on the form with the desired format mask. For 
     example, [99999.99] or [0.990] automatically inserts leading zeroes.
 
     The form expressions convert the number to text for use with the format 
     mask and back to a floating-point value for storage in the table. The 
     expressions must be in the order shown, with the column expression first. 
 
     The variable must be defined first as a TEXT datatype.
 
     Right Justify Currency Values in Forms
     ======================================
     Format masks cannot be used to justify or center fields - they are only 
     character modifiers. You can, however, use the FORMAT function (new in 
     R:BASE 3.1C) and the new R:BASE 4.0 cap-ability of the FLOAT function 
     to accept currency and text arguments to do this.
 
     The FORMAT function converts the currency value to text and specifies 
     the display format. The variable is placed on the form. Then use the 
     FLOAT function to reconvert the edited text value to CURRENCY and store 
     the result in the column.
 
     The field does not left justify for data entry. You'll need to move the 
     cursor over to the data to change it. 
 
     To modify tranform in the CONCOMP database so that the price and 
     extended price fields in the transdetail table are right justified, 
     add the following expressions to the form in the transdetail table in 
     the order shown below. Both the PRICE column and the EXTPRICE column 
     display as justified - both are actually located on the form as vari-
     ables. Since the extprice column is a computed column, the variable 
     located on the form also does the computation. (See diagram below)
  
 
       price       CURRENCY  =       (FLOAT(.vprice)*$1)
       vprice      TEXT      =       (FORMAT(price,'[>$999,999,999.00'))
       veprice     CURRENCY  =       (FLOAT(.vprice)*units*$1)
       vextprice   TEXT      =       (FORMAT(.veprice,'[>$999,999,999.00'))
 
 
     The expression PRICE =(FLOAT(.v-price)*$1) reconverts the text represen-
     tation of the price to currency and loads the changed value into the 
     table. The vprice expression uses the FORMAT function to create a justi-
     fied and formatted text variable to locate on the form. Be sure to 
     modify the field settings on vprice so you can edit the data.
 
     Make sure the located fields (vprice, vextprice) are wide enough for 
     the entire format to display. In the above expressions, the field must 
     be 16 characters wide (one for each character of the format, including 
     commas and decimal point, and one extra character for the minus sign if 
     the number is negative).
 
     Because vprice is used in a calculation, character modifiers (for 
     example, ( ) to enclose negative numbers) cannot be used as part of 
     the format. When the conversion from TEXT back to CURRENCY is done the 
     value becomes null if it contains other characters.
 
     You can use the same technique to right justify integer or double values 
     or to specify a particular number of decimal places.