Microsoft KB Archive/103467: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
Line 12: Line 12:
== SUMMARY ==
== 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.
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 ==
== MORE INFORMATION ==
Line 29: Line 29:
       USE PADTEXT
       USE PADTEXT
       GO TOP
       GO TOP
       WAIT WINDOW "demonstrating PADL function"
       WAIT WINDOW "demonstrating PADL function"
       REPLACE FIELD1 with "12345"
       REPLACE FIELD1 with "12345"
       WAIT WINDOW "PADL with untrimmed left-justified data"
       WAIT WINDOW "PADL with untrimmed left-justified data"
       REPLACE FIELD1 with PADL(FIELD1,10)
       REPLACE FIELD1 with PADL(FIELD1,10)
       * you will see the data hasn't 'moved' to the right as expected *
       * you will see the data hasn't 'moved' to the right as expected *
       WAIT WINDOW "result of PADL:" + FIELD1
       WAIT WINDOW "result of PADL:" + FIELD1


       WAIT WINDOW "PADL with trimmed left-justified data"
       WAIT WINDOW "PADL with trimmed left-justified data"
       REPLACE FIELD1 with PADL(ALLTRIM(FIELD1),10)
       REPLACE FIELD1 with PADL(ALLTRIM(FIELD1),10)
       * you will notice the data has 'moved' to the right as expected *
       * you will notice the data has 'moved' to the right as expected *
       WAIT WINDOW "result of PADL:" + FIELD1
       WAIT WINDOW "result of PADL:" + FIELD1


       WAIT WINDOW "demonstrating PADR function"
       WAIT WINDOW "demonstrating PADR function"
       GO TOP
       GO TOP
       REPLACE FIELD1 with "     12345"
       REPLACE FIELD1 with "     12345"
       WAIT WINDOW "PADR with untrimmed right-justified data"
       WAIT WINDOW "PADR with untrimmed right-justified data"
       REPLACE FIELD1 with PADR(FIELD1,10)
       REPLACE FIELD1 with PADR(FIELD1,10)
       * you will see the data hasn't 'moved' to the left as expected *
       * you will see the data hasn't 'moved' to the left as expected *
       WAIT WINDOW "result of PADR:" + FIELD1
       WAIT WINDOW "result of PADR:" + FIELD1
       WAIT WINDOW "PADR with trimmed right-justified data"
       WAIT WINDOW "PADR with trimmed right-justified data"
       REPLACE FIELD1 with PADR(ALLTRIM(FIELD1),10)
       REPLACE FIELD1 with PADR(ALLTRIM(FIELD1),10)
       * you will notice the data has 'moved' to the left as expected *
       * you will notice the data has 'moved' to the left as expected *
       WAIT WINDOW "result of PADR:" + FIELD1
       WAIT WINDOW "result of PADR:" + FIELD1


       WAIT WINDOW "demonstrating PADC function"
       WAIT WINDOW "demonstrating PADC function"
       GO TOP
       GO TOP
       REPLACE FIELD1 with "     12345"
       REPLACE FIELD1 with "     12345"
       WAIT WINDOW "PADC with untrimmed data"
       WAIT WINDOW "PADC with untrimmed data"
       REPLACE FIELD1 with PADC(FIELD1,10)
       REPLACE FIELD1 with PADC(FIELD1,10)
       * you will see that the data hasn't been centered as expected *
       * you will see that the data hasn't been centered as expected *
       WAIT WINDOW "result of PADC:" + FIELD1
       WAIT WINDOW "result of PADC:" + FIELD1
       WAIT WINDOW "PADC with trimmed data"
       WAIT WINDOW "PADC with trimmed data"
       REPLACE FIELD1 with PADC(ALLTRIM(FIELD1),10)
       REPLACE FIELD1 with PADC(ALLTRIM(FIELD1),10)
       * you will notice the data has been centered as expected *
       * you will notice the data has been centered as expected *
       WAIT WINDOW "result of PADC:" + FIELD1
       WAIT WINDOW "result of PADC:" + FIELD1
       ** end of program **
       ** end of program **
</pre>
</pre>

Revision as of 09:26, 20 July 2020

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

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


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