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

ID: Q103467

The information in this article applies to:

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

Last Reviewed: June 27, 1995