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

Duplicate characters in string 1

Status
Not open for further replies.

karole

Technical User
Nov 14, 2009
4
US
In Crystal Reports, I'm using this piece of code to concatenate characters in a string in the details section.

WhilePrintingRecords;
StringVar OptSuffix;

OptSuffix:= OptSuffix + Trim({options.number})

The options table has many value choices - ranging from A-Z and 0-9 - and some of the choices have 2 character values. ie... P1, P2, P3 and U1, U2, U3, etc...
The code seems to work fine in stringing all the characters together except when the Option.Number value begins with the letter "U". When the U# value is used, the string results in duplicating this value in the string. ie... values A,B,C,P1,U1 would result in ABCP1U1U1. Any idea why this would be happening?
 
Hi,
Have you verified that the

A,B,C,P1,U1

data comes from only 5 records and still creates the
6 value string

ABCP1U1U1
?




[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
After experimenting with the report a little more, I've discovered what seems to be triggering the duplicate suffix string - I just don't know how to fix it.
Basically, I have 3 tables in the relationship. Part Number, Options, and Notes. The Part Number is the main data and needs to get reported, regardless if a Part Number has Options or Notes associated. If I understand it right, I need to change both link types to be Left Outer Join to make this happen. Using the Outer Join does report all the Part Numbers... but, if the Part Number has options, the last value in the options string is duplicated. If I change the Join Type back to Inner Join - the option string is correct but it doesn't report any of the Part Numbers that don't have Options.
 
Try changing the formula to:

WhilePrintingRecords;
StringVar OptSuffix;
if not(Trim({options.number})+"," in OptSuffix) then
OptSuffix:= OptSuffix + Trim({options.number}) +",";

Then in the display formula, you can remove the commas if you wish:

WhilePrintingRecords;
StringVar OptSuffix;
replace(OptSuffix,",","")

This would give you unique values and also, by adding in the comma, distinguish "P" from "P1", for example, when determining what is unique.

-LB
 
Thanks, LB. That seems to have worked. Although, this past weekend I was working on the report on a Vista machine and the problem didn't exists. I saved the report and brought it to work (XP machine) and I get the duplicates again. I tried your code on the XP machine and... Voila! No duplicates. Now, if I can take the report back to the Vista machine and have no duplicates... I would say you're my new best friend!!
Again, thank you very much!

By the way, do you happen to know how to make an alert for when the option.number value contain a dot "."?
 
Create an alert with a condition like this:

instr({options.number},".") > 0

-LB
 
Tried that one. The message box just doesn't show up. I even tried switching out the character - from '.' to 'T' (and others I know are present) but I just can't make it display. The report is being utilized through another application so it could be some issue within the app. I'll keep working with it. Thanks!
 
Alerts only pop up when you refresh the report. I'm not sure how this would work with another application.

Instead of using an alert you could do something like highlight records using the formula:

if instr({options.number},".") > 0 then
cryellow else
crnocolor

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top