Format Expressions for Field Controls
You can create a variety of formats for output generated from Field controls by creating a format string expression. A format string contains format codes and format templates.
Format Codes
Format codes apply to all the characters in the Field control expression and must be preceded by the at sign (@) in the format string. For example, you can pad a numeric value with leading zeros instead of spaces by using the format string "@L 999999".
Format Code: |
Description: |
Applies to data of type: |
---|---|---|
! |
Force text to uppercase. |
Character only |
B |
Left justify . |
All types |
J |
Right justify. |
All types |
I |
Center justify. |
All types |
L |
Leading zeros. |
Numeric only |
Z |
Blank if zero. |
Numeric, Date, and DateTime |
( |
Surround negative numbers with (). |
Numeric only |
C |
Appends " CR" to positive, non-zero numbers. |
Numeric only |
X |
Appends " DB" to negative, non-zero numbers. |
Numeric only |
$ |
Uses currency notation. |
Numeric only |
D |
Use current SET DATE setting. |
All types |
E |
Display as if SET DATE BRITISH was in effect. |
All types |
YL |
Display using system Long Date format. |
Date |
YS |
Display using system Short Date format. |
Date |
R |
Prevents non-formatting characters in the template string from replacing the corresponding character of the field expression value. When @R is used, the template string interleaves instead of overlaying. (See example below.) |
Character and Numeric |
Notes
Numeric data is right-justified by default.
Character and Date data are left-justified by default.
You can use combinations of format codes. For example "@CX" will display both credits and debits on numeric data, where appropriate.
For more information about how format codes are used in form controls, see Format Property.
Template Characters
Format template characters apply to individual characters in the Field control expression. You can create a pattern with format template characters with each character in the template representing a character you want to display. For example, some characters in a format template alter the display of specific character types. For example, including the character "Y" in a format template for a logical expression displays the letters "Y" instead of ".T." for True and "N" instead of ".F." for False. The character "9" in a format template is a placeholder for any digit in character or numeric data. Other format template characters, such as parentheses, spaces, and hyphens, display as themselves.
For more information about format template characters, see InputMask Property.
Examples
The following examples show how format codes and format template characters work together to create the output:
Field Expression Value |
Format String |
Rendered Output |
---|---|---|
-43.05 |
@(CX 999.999 |
( 43.050 DB) |
65.43 |
(999) 999-9999 |
( ) - -43 |
"4505551023" |
(999) 999-9999 |
(505) 102- |
"4505551023" |
@R (999) 999-9999 |
(450) 555-1023 |
ca90210 |
@R !! 99999 |
CA 90210 |
See Also
Tasks
How to: Specify Data Types for Field Controls