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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format Zip Code 1

Status
Not open for further replies.

dcusick

Technical User
Aug 9, 2000
271
US
Hi everyone... Quick question for you guys... A company created an application for us that fills in a MS 97 Database. I had to create a VB6 component that would use this database to display certain information. My only problem is coming when I try to output the Zip Code in 00000-0000 format. The company formatted the field as text with a 20 character max. If a user doesn't enter the 4 digit extension, the info in the database is saved as only 5 characters, not 9.

Example 1: If I entered 12345- as the users Zip, it would show up as 12345.
Example 2: If I entered 12345-6789, it would show up as 123456789.

In my VB App, I started off by using the format(zip,"00000-0000"). This is fine for Ex. 2, but shows up as 00001-2345 for Ex. 1. I need to use left justification always. So I tried to use format(zip,"!00000-0000"). When I ran this, it always showed zeroes, 00000-0000. Any ideas would be greatly appreciated. Thanks.

Doug

 
Perhaps you could try something like the following:

zip = format(zip, IIf((len(zip) < 6), &quot;00000&quot;, &quot;00000-0000&quot;)) Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thank you for the response, and a good idea. I just need the output to be the same across the board. So I just had to make your suggestion a little more complicated. I used:

lblZipCode.Caption = IIf(Not IsNull(zip), IIf(Len(zip) < 6, Format(zip, &quot;00000&quot;) & &quot;-0000&quot;, Format(zip, &quot;00000-0000&quot;)), &quot;&quot;)

It's a little wordy, but it works. Thanks Cajun!

Doug
 
Looks good dcusick Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top