I’m new on crystal reports and don’t have much knowledge of programming. I’m looking for a formula that will separate the notes (example: To Syd+We miss you+From Bill&Pat) into 3 different field. Any help would be greatly appreciated.
local stringVar subject := 'To Syd+We miss you+From Bill&Pat';
local numberVar location := instr(subject, '+');
if location > 0 then
left(subject, location)
else
subject;
I have hardcoded the string to be modified, but you can replace it with {table.field}
Also, if there will definitely always be + you can simplify things by removing the if.
a note that Lee's answer will get you the leftmost bit of text only.
instr(subject,"+") returns the location of the leftmost presence of +
left(subject,location) pulls out a chunk of subject of 'location' number of characters
if you then wanted to fish out the second and third bit, you could do this:
local stringvar subject := "string1+string2+string3";
local numberVar location1;
local numberVar location2;
location1 := instr(subject, "+");
location2 := instr(location1+1, subject, "+");
/////this instr only starts to look from location1 for the next leftmost + and I'll show below how you can use
( if location1 > 0
then left(subject, location1-1)
/////use Lee's 'left' command to bring up the first bit, I added the minus1 so that the actual + would not show
else "missing first +" )
+chrw(13)+ //I was displaying this on screen so I added a ENTER, you can get rid of this line
( if location2 > 0
/////error checking is sanity-saving sooner or later
then
(
mid(subject, location1+1, location2-1-location1)
/////pulls a chunk from within subject, starting at location1+1 [to get past the + at location1 itself],
/////going rightward to grab 'location2-1-location1' characters
/////(play a few times with the +1/-1 to get hte idea.
/////try it with a two-character seperator, say "To john12Hello12From jane", helped me get my head straight
+ chrw(13)+ //again, this is just for my proofing
right(subject, length(subject)-location2)
/////pulls a chunk from the right of subject, of size 'length of subject' minus location2,
/////so everything from the end until hit that +
)
else "missing second +" )
Related
I have a field in crystal reports that displays customer's names. the requirement however is to just display the first 5 characters, which includes spacing as well. whatever comes after the 5th character will be converted into * and the spacing shall be displayed as a space still. as the name field varies, how do i accomplish this?
currently i only have this, which displays the first 5 characters and replaces only the 6th character with an *
Replace({Command.CUST_NAME},MID({Command.CUST_NAME},6),"*")
Unfortunately, it seems Crystal does not suport regex.
So, i would do a function. Try this:
stringvar input := {Command.CUST_NAME};
stringvar output := MID(input, 1, 5);
numbervar i;
for i:=5 to Length (input) step 1 do (
stringvar aChar := MID(input, i, 1);
if aChar <> " " then aChar := "*";
output := output + aChar;
);
output
Maybe you will have to handle if {Command.CUST_NAME} is smaller than 5 chars.
I need advanced help with the proper case function in crystal reports. I'm using the following formula for individual first and last name fields which work great.
ProperCase ({table.field})
My issue is finding a way to fix the "T" in my address example below. The "T" needs to read "t" after the 8.
8Th Street Apt
See screenshot: Address Error
Address formula:
ProperCase ({table.address1}) + " " + ProperCase ({table.address2})
The format looks silly when sending it this way to employees. Please comment your suggestions!
Try this?
stringvar array ins := split({table.address1} + " "+ {table.address2}," ");
stringvar out;
numbervar z := ubound(ins);
numbervar y;
for y := 1 to z DO
(
if asc(left(ins[y],1)) in [97 to 122] then ins[y] := propercase(ins[y]) ;
);
out := join(ins," ");
out
I am creating a report by Crystal Reports which will mask address field depending upon parameter set to the report. I know this can be done using formula. I can successfully mask with hard coded value. However I need something like password masking. For example, if address is D/302 ABC apartment, it should be displayed as X/XXX XXX XXXXXXXXX. Only characters and numbers to be masked space and special characters not be masked. In addition length of masked data should match actual data.
I think you can use a formula like this:
Local StringVar str := "";
Local NumberVar strLen := Length({User.Address});
Local NumberVar i;
For i := 1 To strLen Do
(
if (ChrW({User.Address}[i]) in (AscW("A") to AscW("Z"))) or (ChrW({User.Address}[i]) in (AscW("a") to AscW("z"))) or (ChrW({User.Address}[i]) in (AscW("0") to AscW("9"))) Then
str := str + "X"
else
str := str + {User.Address}[i];
);
str
Logic is correct.. I have done the same thing by using Mid function instead of chrW (). No need to use asw () either. Simply use range operator.
Logic is correct.. I have done the same thing by using Mid function instead of chrW (). Additional you can use formula as ReplicateString ("X",len(address));
Only problem is space will be also masked
Similar to my first question. I want to show my address in a text box containing the fields as follows
{Company}
{AddLine1}
{AddLine2}
{ZIP}{State}{City}
{Country}
The line that concerns me (and hopefully some of you guys) is {ZIP} {City} {State}. What I want to produce is a consistent addressing format, so that there will be no blank space or indentation even if a ZIP, City or State field has been left blank in the DB. This line should still line up with the rest of the rows and not be indented. I also wish to insert commas between zip, state, city where they are relevant and leave them out where not. For this I have written a formula. Below:
If isnull({BILL_TO.ZIP}) or trim({BILL_TO.ZIP})= "" Then "" else {BILL_TO.ZIP}
+
(If isnull({BILL_TO.State}) or trim({BILL_TO.State})= "" Then ""
else(If not isnull({BILL_TO.ZIP}) and length(trim({BILL_TO.ZIP})) <> 0 Then ", " else "") + {BILL_TO.State})
+
(If isnull({BILL_TO.CITY}) or length(trim({BILL_TO.CITY})) = 0 Then ""
else(
If (not isnull({BILL_TO.State}) and length(trim({BILL_TO.State})) <> 0)
or
(not isnull({BILL_TO.Zip}) and length(trim({BILL_TO.Zip})) <> 0)
Then ", " else "")+ {BILL_TO.CITY}))
The problem is that when there is only a city (no state or zip entered) the formula itself will not display. It does however display when the others are present.
Can anyone see a bug in this code??? Its killing me
Thanks for the help.
Look forward to hearing from you guys!
There are a whole lot of if-then-elses going on in that formula so it's hard to tell, but if it's not displaying anything that probably means that you're using a field somewhere without handling its null condition first. Something simpler might be your best bet:
local stringvar output;
if not(isnull({Customer.Postal Code})) then output:=trim({Customer.Postal Code}) + ', ';
if not(isnull({Customer.Region})) then output:=output + trim({Customer.Region}) + ', ';
if not(isnull({Customer.City})) then output:=output + trim({Customer.City}) + ', ';
left(output,length(output)-2)
Create a formula field for each database field. For example:
// {#CITY}
If Isnull({BILL_TO.CITY}) Then
""
Else
Trim({BILL_TO.CITY})
// {#STATE}
If Isnull({BILL_TO.STATE}) Then
Space(2)
Else
Trim({BILL_TO.STATE})
// {#ZIP}
If Isnull({BILL_TO.ZIP}) Then
Space(5) //adjust to meet your needs
Else
Trim({BILL_TO.ZIP})
Embed each formula field in a text object.
Format text object and its fields to meet your need.
** edit **
I you have data-quality issues, address them in the STATE and ZIP formulas (because they will be a constant length). I would add the commas and spacing the text object.
I have a list of words that I am searching through a "Notes" field within a table, that when I display that Notes field in my Crystal Report, I would like to somehow highlight (change font color) for only the specific flagged word within the note text string.
Example:
word list: Joe, Sarah, Amy, Jeff
note text: "I stopped by and talked with Joe to check on the account status, and Amy said hello."
desired result: Note text displays in the report with the words "Joe" and "Amy" in red.
I've tried using RTF and HTML in the Text Interpretation parameter within the properties, where I can successfully format the note text to either of these text outputs. However, I still don't know the right code to isolate and format the specific words from my list, especially if more than one of my words shows up within the field text.
Thanks in advance for any help you can give me!
I know this is old, but i found it searching for an issue i had. The answered code works, but seemed a bit cluttered for me, and also i needed to be able to provide a list of words to highlight. Here is what i came up with.
Local Stringvar Array searchwords:=MakeArray("Joe", "Sarah", "Amy");
local stringvar notes:={Notes};
local numbervar i;
for i:=1 to count(searchwords) do (
notes:=replace(notes,searchwords[i],"<font color='red'>" & searchwords[i] & "</font>",1,-1,1);
);
notes
The only thing to note, is that this will find results when the search word is part of a larger word - i.e. "WORK" would be BOLDED in "Workshop".
While this works for our needs as we want "working","work","worked" etc. to all highlight, crystal reports not supporting Regex is quite a large downside.
I did something similar a couple of years ago:
StringVar SearchText := "has";
StringVar Htm1 := "<b>";
StringVar Htm2 := "</b>";
StringVar Result := "";
StringVar Temp := "";
NumberVar Start := 1;
NumberVar Ln := Len(SearchText);
NumberVar Loc := Instr({#TextField}, SearchText);
While Loc > 0 Do (
Temp := Mid({#TextField}, Start, Loc - Start) + Htm1 + Mid({#TextField}, Loc, Ln) & Htm2;
Result := Result + Temp;
Start := Loc + Ln;
Loc := Instr(Start, {#TextField}, SearchText);
);
Temp := Mid({#TextField}, Start);
Result := Result + Temp;
Result
In this case I am searching the field called #TextField for the value in SearchText and am bolding the values. Probably not the most efficient code, but it works.