Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Zero's to a text field

Status
Not open for further replies.

BlurredVision

Technical User
Aug 6, 2001
326
GB
Hello all - I am creating a report to be exported to a text file and I need to create a formula to add zero's to a zip code field if the length of the field is not equal to 9.

I am using crystal reports v10 and here is what I have so far:

stringvar zipcode := replace({RV_Practitioner_Offices_V.Zip_Code},"-","");

if len(trimleft(zipcode)) = 9 then
zipcode else

if len(trimleft(zipcode)) = 5 then
zipcode + "0000" else

if len(trimleft(zipcode)) = 0 then
"000000000"

My question is, my formula is somewhat cumbersome in dealing with every possible circumstance, and does anyone have a better example on how to handle this?

Here is a example on how the database might appear:

60714-4568
60714
607-
6071

Thanks..


 
Hi,
Try something like This:
Code:
numberVar ctr;
stringVar NineDigitZip := "";
If Length(Trim({zipcode})) < 9 then
(
for ctr := 1 to 9 - Length(Trim({zipcode})  do
(NewLongName := NineDigitZip + "0");

Trim({zipcode}) + NineDigitZip
)
else
Trim({zipcode})

Use this formula instead of the zipcode field..



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top