FORMAT$

Contents


format$ is used to format an expression based on a particular format.

Syntax

   format$( expr_c, exp )

Parameters

Element

Description

Restrictions

expr_c

Expression of the type Char containing a valid format.

Format adapted to the expression type

exp

Numerical, alphanumerical or date expression.

None.

Examples

   CHFOR   = format$("D:[In Paris, the ]DD[ ]9M[ ]YYYY", date$)
   CHTOTAL = format$("N3Z:12.2[ Francs]", sum(TTC))

Description and comments

format$( expr_c, exp ) returns the exp expression formatted according to the expr_c format.

The result type is Char.

A format is written as a string of characters separated by a ":" according to the following diagram:
Type/General options/Particular options: formatting string

°Type

The possible types are:

It is possible to add n secondary options (n can be nul). They are dependent on the general option. The order in which they are named is of no importance. An unknown option will be ignored without an error being generated.

common OPTION for all field types

Code

Code meaning

<

Left alignment     ( obsolete)

>

Right alignment     ( obsolete)

=

Center alignemnt     (obsolete)

c

Display of a field in color according to the pcolor variable (managed only on the fields in a grid block)

z

No display (not even the comments) when the value to be displayed is null.

°Displayed field

X

Masked entry

C

Total field mandatory

B

Display of spaces instead of the comments

G

Beep if error

Example :
format$("N:9.2[ Francs]",0)      -> " 0,00 Francs"
format$("Nz:9.2[ Francs]",0)     -> " "

OPTION  for the ALPHANUMERICAL fields

Code

Code meaning

A

Necessary to enter the requested uppercase or lowercase characters.

T

Tokenization (that is to say understanding of key words in the entry of a calculation formula)

TD

No key words authorized

b

Addition of blanks to complete the field end.

v

Deletion of the blanks. The vireblc option is mentioned following the v code.

vn (with n ranging from 0 to 5) is used to apply the n option of the vireblc function to the resulting string.
Examples:
format$("Kv0:20X"," A B C ")     -> "A B C "
format$("Kv1:20X"," A B C ")     -> " A B C"
etc
format$("Kv5:20X"," A B C ")     ->" A B C "
Nota : this is the only case where the length of the resulting string is smaller than the one specified by the formatting string.

OPTIONS  for NUMERICAL fields

Code

Code meaning

A

Display of blanks instead of the planned character should the numerical capacity be exceeded.

D

Display of the sign behind the number.

F

Floating numbers

Z

Addition of zero, at the end of the decimal part.

+

Positive numbers

-

Systematic display of the sign

*

Complete with * in front of the number

0

Complete with 0 in front of the number

3

Separator of 3-figure groups of the integer part (obsolete)

NB: should the numerical capacity be overflown, in other words when, in the formatting string, the number of figures before the decimal separator is too small for the number to be displayed, no error is generated, the resulting string is loaded with the character defined as being the "numerical capacity overflow character". The latter is defined y the Adonix [S]adxsca variable. It is the 5th character of this string. We saw earlier that the secondary option A makes it possible to change this behavior.

For instance: (with mid$([S]adxsca,5,1) = "*" )
format$("N:6.2",1234567.12)     -> "******,**"
On the other hand, the decimal part will be truncated if it is too small.
Example :
format$("N:3.2",123.456)             -> "123,45"

The separator between 3-figure groups is the 3rd character of [S]adxsca but it is not used (obsolete).
The decimal separator is the 4th of this [S]adxsca variable.

OPTIONS  for DATE fields

Code

Code meaning

Z

Blank date authorised

formatting string

The formatting string describes the characters used to display the string and included comments.

Comments

They can be placed at the beginning of the string, in the middle or at the end of the string.
They are demarcated using the "[" and "]" characters.
Example :
format$("D:[Le ]DD[ du mois de ]MMMMMMMM",date$)         -> "The 12th of the month of January"

String characters

It is possible either to give a character by position or to mention the number of characters by a number preceding the character.
For instance:
format$("LA1:XXX",OK) is identical to format$("LA1:3X",OK)

The possible codes are dependent on the type of expression to be displayed and thus on the primary formatting option. There are standard codes, defined by Adonix and some defined by the [S]adxtuc, [S]adxtul and [S]adxtut variables. Here is a grid with the main Adonix codes.

Code

Types

Code meaning

X

K

Any printable characters.

#

N

Number (0 to 9). Default type in case of a repetition factor followed by a "." For instance, 12.2 is a number containing 12 positions and 2 decimal places

.

N

Position of the decimal separator in fixed format.

F

N

Number with floating format.

A

K

Uppercase letters (A to Z). Automatic conversion except in case of option A.

a

K

Lowercase letters (a to z). Automatic conversion except in case of option A.

L

K

Upper and lowercase letters (A-Z, a-z)

B

K

Uppercase letters and figures (A-Z, 0-9)

b

K

Lowercase letters and figures (a-z, 0-9)

C

K

Uppercase and lowercase letters and figures (A-Z, a-z, 0-9)

H

K

Hexadecimal numbers (0-9, A-F)

 

K

Spaces

D

D

Day of a date

M

D

Month of a date

Y

D

Year of a date

h

D

Hours

m

D

Minutes

s

D

Seconds

Remarks

The # and F codes can be used with the K and L types, provided that the strings to be displayed contain numbers only. Otherwise, the resulting string will only contain spaces. It is indeed the case when one of the characters to be displayed is not compatible with the requested format. For instance:
format$("K:10#","12345.6")          -> " "

For character strings and local menus, the "X" type is the most widely used since it does not show unexpected results.

For the dates, let us notice that:

For the years, the only acceptable formats are 2Y and 4Y.

Associated errors

Error

Description

ERMODE (10)

The value of expr_c is not of Char type.

Associated keywords

MESSNAME - ADXSCA - ADXTUL - ADXTUC - ADXTUT


CONTENTS

Copyright © Sage 1999 - 2007