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!

Trim or no trim 1

Status
Not open for further replies.

drinker

Technical User
May 9, 2006
57
US
I need a formula to dispaly 'true' if the following is true; ex:

{part.material_code} {part.id}

0800-0836 0800C-0836-A
380C-010 380C-009-5


The above fields are to show 'true' because they are not the same.

0742C-0151-10 0742C-0151
410D-E01-12 410D-E01

These need to show false as they are the same minus the last digits on the {part.material_code} side. These digits are the rev and can be 1 or 2 digits long. They could also be letters.

To sum up, I need to show on my report only the parts with the same part numbers minus any revs on thre material code side. I hope i made it clear. Thank You.

 
Interesting one.

Try:

whileprintingrecords;
stringvar code:={part.material_code};
stringvar id:={part.id};
stringvar NewCode:="";
stringvar NewID:="";
numbervar x;
numbervar HyphenCnt:=0;
For x:=1 to len(code) do(
if mid(code,x,1) = "-" then
HyphenCnt:=HyphenCnt+1;
if HyPhenCnt < 2 then
NewCode:=mid(Code,x,1)
);
HyphenCnt:=0;
For x:=1 to len(id) do(
if mid(id,x,1) = "-" then
HyphenCnt:=HyphenCnt+1;
if HyPhenCnt < 2 then
NewID:=mid(ID,x,1)
);
NewCode=NewID

Can't test right now, but it looks sound.

-k
 
Almost there. I have a couple that should be 'true but are coming up false;

{part.id} {part.material_code}

DDF2-F1-410 DDF2-F1-401
DDF2-F1-402 DDF2-F1-402
 
Sorry they are:

{part.id} {part.material_code}

DDF2-F1-401 DDF2-F1-401
DDF2-F1-402 DDF2-F1-402


Also I have one that should be true;

0730A-0043-B 0730A-0043-A
 
Place 2 formulas in the details to show what is being generated by the formula:

whileprintingrecords;
stringvar NewID:="";

whileprintingrecords;
stringvar NewCode:="";

It still looks sound to me, perhaps it's a trim issue:

whileprintingrecords;
stringvar code:=trim({part.material_code});
stringvar id:=trim({part.id});
stringvar NewCode:="";
stringvar NewID:="";
numbervar x;
numbervar HyphenCnt:=0;
For x:=1 to len(code) do(
if mid(code,x,1) = "-" then
HyphenCnt:=HyphenCnt+1;
if HyPhenCnt < 2 then
NewCode:=mid(Code,x,1)
);
HyphenCnt:=0;
For x:=1 to len(id) do(
if mid(id,x,1) = "-" then
HyphenCnt:=HyphenCnt+1;
if HyPhenCnt < 2 then
NewID:=mid(ID,x,1)
);
NewCode=NewID

-k
 
This is what I get from both formulas:

0730A-0043-B 0730A-0043-A True True
0740C-0151-10 0740C-0151 True True
0740C-0151-11 0740C-0151 True True
0742C-0151-10 0742C-0151 True True
0745C-0151-10 0745C-0151 True True
0746C-0151-10 0746C-0151 True True
0747C-0151-10 0747C-0151 True True
074EC-0151-10 074EC-0151 True True
0800C-0836-A 0800-0836 True True
0840C-0003-10 0840C-0003 True True
0870C-0001 0870A-0025 False False
380C-009-5 380C-010 False False
380D-E02-18 380D-E02 True True
380D-E02-19 380D-E02 True True
410D-E01-12 410D-E01 True True
410D-E01-13 410D-E01 True True
550A-S01-11 550A-S01 True True
550C-001-10 550C-001 True True
700D-E03-12 700D-E03 True True
DDF2-FI-401 DDF2-F1-401 False False
DDF2-FI-402 DDF2-F1-402 False False
P-550A-S01-10 P-550A-S01 True True
P-550A-S01-11 P-550A-S01 True True
UITF01-001 UITF01-01 True True

 
Sorry, you should have used:

whileprintingrecords;
stringvar NewID;

whileprintingrecords;
stringvar NewCode;

to test, and make sure you use the TRIM version of the formula that I posted.

-k
 
Sorry, Is this the formula with the corrections:

whileprintingrecords;
stringvar NewID:="";

whileprintingrecords;
stringvar NewCode;

whileprintingrecords;
stringvar code:=trim({part.material_code});
stringvar id:=trim({part.id});
stringvar NewCode:="";
stringvar NewID;

numbervar x;
numbervar HyphenCnt:=0;
For x:=1 to len(code) do(
if mid(code,x,1) = "-" then
HyphenCnt:=HyphenCnt+1;
if HyPhenCnt < 2 then
NewCode:=mid(Code,x,1)
);
HyphenCnt:=0;
For x:=1 to len(id) do(
if mid(id,x,1) = "-" then
HyphenCnt:=HyphenCnt+1;
if HyPhenCnt < 2 then
NewID:=mid(ID,x,1)
);
NewCode=NewID

 
Yep, the problem is that some of your fields are padded with spaces, so the trim eliminated them.

-k
 
Seems that this Part Number doesn't fit the formula.

{Part.ID} {part.material_code}

0620C-0008-1 0620C-008

This should show up on the report because 0008 and 008 do not match. The -1 should be taken out of the criteria.

Crystal 8.5
 
You could try a different approach, a boolian saying
Code:
{part.material_code} in {part.id}
This would give you 'true' for Part.ID 00620C-0008-1 and part.material_code 0620C-008, which I assume you don't want. But you could then do a second test,
Code:
Left({part.material_code},3) = Left({part.id},3)
Does that help?



[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Thanks Madawc! {part.material_code} in {part.id} worked great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top