Using AFIELDS() to Determine Number of Decimal Places

Last reviewed: June 27, 1995
Article 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 "Commands & Functions" manual for FoxPro 2.0 for MS-DOS and the "FoxPro Language Reference" 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,"NUMFLD") + 3)
       ?m.decimals
    
       NOTE: M.decimals should contain a value of 3, which is the number of
       decimal places in the field named NUMFLD.
    
    

REFERENCES

Pages C3-126 and C3-144 of the FoxPro 2.0 for MS-DOS, "Commands &

 Functions".
Pages L3-182 and L3-206-207 of the FoxPro 2.5 for MS-DOS and
  Windows "Language Reference".


Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a
KBCategory: kbprg
KBSubcategory: FxprgGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 27, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.