Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

dunkyn (TechnicalUser) (OP)
23 Jun 03 15:19
I want to remove some repetitive abbreviations from a string of text.  I have placed multiple replace statements in the same formula.  It doesn't seem to be working in all instances.  Looks like it is only recognizing the last replace statement.  

Sample below:

Replace ({table.field1},"INC COM","");
Replace ({table.field1}, " INC" , "");
Replace ({table.field1}, " CORP" , "");
Replace ({table.field1}, " CORP COM" , "");
Replace ({table.field1}, " CO COM" , "");
Replace ({table.field1}, " CO " , "");
Replace ({table.field1}, "COM" , "");


There must be a better way ?
Helpful Member!(2)  IdoMillet (Instructor)
23 Jun 03 18:07
Use something like:
---------------------------------------
StringVar HoldString;

HoldString := Replace ({table.field1},"INC COM","");

HoldString := Replace (HoldString, " INC" , "");

HoldString := Replace (HoldString, " CORP" , "");

HoldString := Replace (HoldString, " CORP COM" , "");

HoldString := Replace (HoldString, " CO COM" , "");

HoldString := Replace (HoldString, " CO " , "");

HoldString := Replace (HoldString, "COM" , "");
-------------------------------------------------

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
www.MilletSoftware.com

Helpful Member!  Ngolem (Programmer)
23 Jun 03 19:05
IDO has done it correctly....the reason yours would not work is that   

Replace ({table.field1},"INC COM","");

Does not update the value of {table.field1} .... it would only display {table.field1} with "INC COM" removed....by assigning it to a variable as he has done and then displaying the variable at the end...you get the desired result AND can use it elsewhere in the report.

I would only add this tiny change...for readability and timing only

WhilePrintingRecords;
StringVar HoldString;

HoldString := Replace ({table.field1},"INC COM","");

HoldString := Replace (HoldString, " INC" , "");

HoldString := Replace (HoldString, " CORP" , "");

HoldString := Replace (HoldString, " CORP COM" , "");

HoldString := Replace (HoldString, " CO COM" , "");

HoldString := Replace (HoldString, " CO " , "");

HoldString := Replace (HoldString, "COM" , "");

HoldString;

Jim Broadbent

Helpful Member!  synapsevampire (Programmer)
23 Jun 03 21:15
Don't be cowards, give yourselves paren headaches!!!

Replace(Replace(Replace(Replace(Replace(Replace(Replace({table.field1},"INC COM","")," INC","")," CORP","")," CORP COM","")," CO COM","")," CO ",""),"COM","")

-k
IdoMillet (Instructor)
23 Jun 03 21:42
Jim, I don't believe there is any scenario under which WhilePrintingRecords would be necessary in this case.  I know that some report developers throw that expression in "just for good measure" but it's not always wise.

Kai, I like the spirit but I always teach my students that when having a choice between a formula that is "easy to debug" (incremental in this case) or a formula that is "compact" or "efficient", they should almost always go with "easy to debug".

Just my own biases...  

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
www.MilletSoftware.com

synapsevampire (Programmer)
23 Jun 03 21:57
<chucklin>

You're faaaar too easy on 'em, Ido, I should have slipped in a Wwitch for good measure ;)

-k
Ngolem (Programmer)
23 Jun 03 23:06
IDO....I said that this was a minor change....the more Major Minor change was to finish with the resulting string by itself.

I did not say this was serious...however...in defense of my action...Adding WhilePrintingRecords...never harms and may help....the thing is that we do NOT know the circumstances of the use of this formula so in truth we do not know

And SV....that formula is not very readable and I doubt very much if it is faster than that described by IDO

Jim Broadbent

IdoMillet (Instructor)
23 Jun 03 23:50
Jim,

I believe that adding WhilePrintingRecords would block the resulting formula from participating in any record selection criteria.  Just an example of why throwing it in "just for good measure" is not always the correct thing to do.

On the other hand, I fully understand why many report developers are adding the darn thing almost automatically.  They've wasted too many hours hunting down a problem due to NOT having it in...   
I just think that in this case there is no reason to use it (and some reasons for not using it).

By the way, I assume you are suggesting adding the variable on its own at the end of the formula just as some sort of clarification.  That added step shouldn't make a difference in outcome.

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
www.MilletSoftware.com

dunkyn (TechnicalUser) (OP)
24 Jun 03 8:50
Thank you all.  The HoldString is new to me.  I'll have to try it.  The nested replace works too, but I like the readability of the HoldString.

You guys are great.  Thanks a bunch!
synapsevampire (Programmer)
24 Jun 03 10:10
Jim: just a little levity...

Ido: I meant to say I should have tossed in a few Switches ;)

-k
Ngolem (Programmer)
24 Jun 03 10:22
IDO - IT IS OBVIOUS - that you never put "WhilePrintingRecords" into a record selection formula...after all...read the name of the function

The formula in question is being used for manipulation of existing data....for future use or current printing, it is unclear, but definately NOT for record selection.

I will give you that perhaps...though very unlikely...it may be used for grouping data and in which case you are correct...this function should not be used there either.

My real purpose of making the addition to your post was not to correct it....but rather to explain the reason for its use. You presented an answer without an explanation as to why the user's approach was wrong...hence he would be prone to make a similar mistake in the future...

SV - the levity was misplaced here

Jim Broadbent

synapsevampire (Programmer)
24 Jun 03 10:35
Ido: The use of any variable appears to block it's use (bby that I assume you mean passing the result on to the database) in the record selection formula.

-k

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close