You can use the first line to just get the 5 digits, or all 3 to get the whole formatted zip. This assumes that the zip is stored as a string.
{zip} [1 to 5 ]
+ "-" +
{zip} [6 to 9 ]
Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Guide to Crystal in VB
If your original field is a number, then try the following to avoid trimming leading zeros, i.e., so you don't lose the leading zero in a zip like 02453-5422:
left(if len(totext({zipcode},0,"") < 9 then replace(space(9-len(totext({zipcode},0,""))," ","0"+totext({zipcode},0,"",5)+"-"+right(if len(totext({zipcode},0,"") < 9 then replace(space(9-len(totext({zipcode},0,""))," ","0"+totext({zipcode},0,"",4)
There might be a simpler way, but this worked when I tried it.
Don, that one might not work. A New Jersey zip code that starts with a zero would be 1 digit short as a number. The dash would end up in the wrong spot.
Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Guide to Crystal in VB
If len({Customer.Postal Code}) = 9 then
{Customer.Postal Code} [1 to 5]+ "-" +{Customer.Postal Code} [6 to 9 ]
else
{Customer.Postal Code}
I'd guess that the zip is NOT a numeric, rather a string, because as Ken pointed out, this can force assumptions to be made, and with Puerto Rico, which starts with 00...
If it is a numeric, you can make assumptions about the length and how to process using something akin to the above.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.