How to Get Desired Results w/ PADL, PADR, PADC Functions

Last reviewed: June 27, 1995
Article ID: Q103467
The information in this article applies to:
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a
  • Microsoft FoxPro for Windows, versions 2.5 and 2.5a

SUMMARY

When you use the PADL(), PADR(), and PADC() functions in FoxPro, the justification of the data in a database field may prevent these functions from producing the desired results. To ensure desired output when using these functions, a "trim" function must be used, either before or along with the PAD<x>() function used.

MORE INFORMATION

To illustrate the effect of using the PAD<x>() functions with untrimmed data, perform the following test:

  1. Create a database called PADTEXT with one character field named FIELD1 with a length of 10. Make sure the database contains one blank record and nothing else.

  2. Run the following program:

          **********************************
    
          * beginning of sample program    *
          **********************************
          USE PADTEXT
          GO TOP
          WAIT WINDOW "demonstrating PADL function"
          REPLACE FIELD1 with "12345"
          WAIT WINDOW "PADL with untrimmed left-justified data"
          REPLACE FIELD1 with PADL(FIELD1,10)
          * you will see the data hasn't 'moved' to the right as expected *
          WAIT WINDOW "result of PADL:" + FIELD1
    
          WAIT WINDOW "PADL with trimmed left-justified data"
          REPLACE FIELD1 with PADL(ALLTRIM(FIELD1),10)
          * you will notice the data has 'moved' to the right as expected *
          WAIT WINDOW "result of PADL:" + FIELD1
    
          WAIT WINDOW "demonstrating PADR function"
          GO TOP
          REPLACE FIELD1 with "     12345"
          WAIT WINDOW "PADR with untrimmed right-justified data"
          REPLACE FIELD1 with PADR(FIELD1,10)
          * you will see the data hasn't 'moved' to the left as expected *
          WAIT WINDOW "result of PADR:" + FIELD1
          WAIT WINDOW "PADR with trimmed right-justified data"
          REPLACE FIELD1 with PADR(ALLTRIM(FIELD1),10)
          * you will notice the data has 'moved' to the left as expected *
          WAIT WINDOW "result of PADR:" + FIELD1
    
          WAIT WINDOW "demonstrating PADC function"
          GO TOP
          REPLACE FIELD1 with "     12345"
          WAIT WINDOW "PADC with untrimmed data"
          REPLACE FIELD1 with PADC(FIELD1,10)
          * you will see that the data hasn't been centered as expected *
          WAIT WINDOW "result of PADC:" + FIELD1
          WAIT WINDOW "PADC with trimmed data"
          REPLACE FIELD1 with PADC(ALLTRIM(FIELD1),10)
          * you will notice the data has been centered as expected *
          WAIT WINDOW "result of PADC:" + FIELD1
          ** end of program **
    


Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a move center left
right
pad
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.