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

Number Length Question

Status
Not open for further replies.

Hashiba14

MIS
May 14, 2007
29
US
I am currently using Crystal 10. I am currently writing a report that currently using 2 fields called dept and item#.

Example of these results are:
Dept = 369
Dept = 471

Item# = 1
Item# = 10
Item# = 100
Item# = 1000

I want to concatenate these 2 fields so that the intended result will be 369-0001 ,369-0010, 369-0100 or 369-1000.

Problem is if I just do a simple concatenation of the 2 fields, I get this: 369-1, 369-10, 369-100.

I need the item number to be a full 4 digits with 0's preceding them.

I tried this formula, but the results all end up with decimal values and I can't seem to edit them.
ex: 369.00-0005.00

stringvar CDM := totext({BSYMMCP.MCITM#},0,"");
if len(CDM) = 1
then ({BSYMMCP.MCDEPT}&"-"&"000"&{BSYMMCP.MCITM#})
else
if len(CDM) = 2
then ({BSYMMCP.MCDEPT}&"-"&"00"&{BSYMMCP.MCITM#})
else
if len(CDM) = 3
then ({BSYMMCP.MCDEPT}&"-"&"0"&{BSYMMCP.MCITM#})
else
if len(CDM) = 4
then ({BSYMMCP.MCDEPT}&"-"&{BSYMMCP.MCITM#})

Suggestions...
 
Dump all the variables, they are not needed. Try this:

{Dept}&"-"&totext({Item},"0000")

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"If you have a big enough dictionary, just about everything is a word"
--Dave Barry
 
Thanks, this helped with the last 4 digits and all I needed to do was apply the same to the first three and it worked.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top