Microsoft KB Archive/97156

{| = Using AFIELDS to Determine Number of Decimal Places =
 * width="100%"|

ID: Q97156

The information in this article applies to:


 * Microsoft FoxPro for Windows, versions 2.5, and 2.5a
 * Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a

SUMMARY
The &quot;Commands & Functions&quot; manual for FoxPro 2.0 for MS-DOS and the &quot;FoxPro Language Reference&quot; manual for FoxPro 2.5 for MS-DOS and Windows do not list an example of using the AFIELDS function. The following example illustrates how the AFIELDS function can be used to help determine the number of decimal places in a field named numfld.

MORE INFORMATION
In the code snippet below, AFIELDS is used to create an array containing field information. The array contains four columns: field name, field type, field length, and decimal places in numeric fields. One row in the array is created for each field in the database structure. The field names and field types are placed in the array as uppercase character strings.

The ASCAN function scans the fldinfo array to find the field named numfld and returns the element number for the field name. The number of decimal places for the field is three elements past the field name.

1. Create a database with the following two fields. Data records do

not need to be added for this example.

Field        Type               Length           Decimals ---

CHARFIELD      C                  10 NUMFLD         N                  10                3 2. USE the database just created. 3. Issue the following commands in the Command window:

?AFIELDS(fldinfo)    && Creates an array named fldinfo. m.decimals = fldinfo(ASCAN(fldinfo,&quot;NUMFLD&quot;) + 3) ?m.decimals

NOTE: M.decimals should contain a value of 3, which is the number of  decimal places in the field named NUMFLD.