Crystal How to split 9-char zip

Posted on 2011-09-15
Medium Priority
Last Modified: 2012-05-12
I have a 9-character zip-code that I would like to be able to split into the format zipfirst5-ziplast4.
How do I code this in a Crystal formula?
Question by:mbroad02
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 36545703

Expert Comment

ID: 36545713
you might not need the totext if the zip is a string
LVL 101

Accepted Solution

mlmcc earned 2000 total points
ID: 36546511
The formula above will not work.  
If the zip field is a string you have to remove the ToText as mentioned.  If it is a number then you have to make sure there are no decimals and no thousand separators and it has to be converted before you use left and right

left(totext({zip},0,""),5) + "-" + right(totext({zip},0,"",4))

Another method.  If it is a string


If it is a number then you would need to add the leading 0's.

Picture(Right("000000000" & CStr({ZipField},0,""),9),"xxxxx-xxxx")

LVL 35

Expert Comment

ID: 36548150
If your zip code is a string, are all of them 9 digits, or do you have some 5 digit zip codes?  If you use Picture and some of your zip codes are only 5 digits, you'll get a "-" at the end.  You can avoid that by using:

if Length ({zip code field}) > 5 then
  Picture ({zip code field}, "xxxxx-xxxx")
  {zip code field}


Author Closing Comment

ID: 36548745
Since the zip-9 is a string, the Picture({ZipField},"xxxxx-xxxx") formula worked perfectly.
Thank you!!

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question