Remove the Alphabet in Crystal Report - crystal-reports

Hi I'm new in Crystal Reports, I'm using Crystal Reports 2008 and I would like to know if how can I remove the alphabet characters in string and only the numbers will remain. Is there function for this?
example: Point 231 / Point 323 / USP 342
output: 231 / 323 / 342
Thanks,
Captain16

Use the following formula
stringvar str;
stringvar str1;
numbervar counter;
numbervar leng;
leng := len({Your_Field});
if leng>0 then
(
for counter := 1 to leng do
(
If (Mid({Your_Field}, counter, 1)) in "a" to "z" Then
(
str1:=str1 + Mid({Your_Field}, counter, 1)
)
else
(
str := str + Mid({Your_Field}, counter, 1)
)
);
str
)
Here the str will get the non-alphabets and str1 will get you only the alphabets from the given string. {Your_Field} can be your field or parameter which contains the string. And by printing str alphabets can be removed...
231 / 323 / 342 this is the output I'm getting for your given input !
Hope this helps, Try and get back with results !

Sorry, I can't comment on Hariharan Anbazhagan's code (I don't have enough reputation it seems). It's good code but I would add LCASE to catch all the captial letters.
If LCASE(Mid({?sample}, counter, 1)) in "a" to "z" Then
There's also a IsNumeric() function if you want to identify just the numbers.

Related

Convert Amount to Words in Crystal Report

I am working on a crystal report, can someone guide me how i can convert currency to words in this format;
(1,502,000.50) One million five hundred and two thousand naira and fifty kobo Only. i have tried:
numberVar x := {#summAmt} - int ({#summAmt});
if x = 0 then
propercase (toWords (int({#summAmt}),0)+ ' Naira Only')
else
propercase (toWords (int({#summAmt}),0)+ ' Naira, and ' + toWords ((x * 100),0) + ' Kobo')
To go around this, you will need 2 formulas; create the one i posted earlier, then create then create another formula with the following code:
numberVar x := {#summAmt} - int ({#summAmt});
if x > 0 then
replace ({#convertWords},"Hundred ","Hundred and " )
else
{#convertWords}
{#convertWords} is the name of my first formula and #summAmt is the name of the field i am converting.

Crystal Reports - formula of full name to initial name

How to display full name in short form like S.M.John in Crystal Reports.
Ex: Database value = Sammual Mbark John.
Need to display => S.M.John
Thank You
Considering your full name can have 2, 3, n names, I think this formula will do the job:
Stringvar result := "";
Local Numbervar i;
Stringvar Array output:= Split({Your.Field}, ' ');
for i := 1 to ubound(output) do (
if i <> ubound(output) then
result := result + left(output[i], 1) + "."
else
result := result + output[i]
);
result
Example and results:
1) "This Is My Test Name" will be "T.I.M.T.Name"
2) "Kurt Donald Cobain" will be "K.D.Cobain"
3) "Barack Hussein Obama" will be "B.H.Obama"
4) "Sammual Mbark John" will be "S.M.John"

Crystal Report Formula - Get numeric from alphanumeric characters

I need a way to extract a numeric value from an alphanumeric one, for example :
3 MS 15 SEC
Desired:
3.15
Try:
Local NumberVar i;
Local StringVar k;
for i:=1 to Count (Split("3 MS 15 SEC"," ")) do
(
if NumericText (Split("3 MS 15 SEC "," ")[i]) then (
k:=k+Split("3 MS 15 SEC "," ")[i]+".";
)
);
if k<>"" then
k[1 to length(k)-1]
else
k //drop final "."
Try:
// {#extract}
Local Stringvar Array tokens:=Split(x);
Local Stringvar Array values;
Local Numbervar i;
for i := 1 to uBound(tokens) do (
if isNumeric(tokens[i]) then (
redim preserve values[ubound(values)+1];
values[ubound(values)]:=tokens[i];
)
);
ToNumber( Join(values,".") );

Display Serial Number as Roman letters in Crystal Reports

need to display serial no as roman letters(i,ii,iii,iv etc) in my crystal reports. I have the serial number captured as record number (1,2,3,4...).so what i have to do for it in crystal report.
Just use the Roman() function provided by Crystal Reports
I can't take much of the credit; I simply ported the code from this VB Helper article into Crystal, but it was a fun exercise:
NumberVar iCounter := 0;
Local StringVar ch := "";
Local NumberVar result := 0;
Local NumberVar new_value := 0;
Local NumberVar old_value := 0;
Local StringVar temp := "";
temp := UpperCase({?#Roman});
old_value = 1000;
For iCounter := 1 To Len(temp) do
(
// See what the next character is worth.
ch := Mid(temp, iCounter, 1);
if ch = "I" then new_value := 1
else if ch = "V" then new_value := 5
else if ch = "X" then new_value := 10
else if ch = "L" then new_value := 50
else if ch = "C" then new_value := 100
else if ch = "D" then new_value := 500
else if ch = "M" then new_value := 1000;
// See if this character is bigger
// than the previous one.
If new_value > old_value Then
// The new value > the previous one.
// Add this value to the result
// and subtract the previous one twice.
result := result + new_value - 2 * old_value
Else
// The new value <= the previous one.
// Add it to the result.
result := result + new_value;
old_value := new_value;
);
// Format the number without commas or decimals
ToText(result, 0, "");
Simply replace my {?#Roman} parameter placeholder with your variable, and you're all set.
I tried to fix it [enter image description here][1]
<https://www.tek-tips.com/viewthread.cfm?qid=887691>
or
<https://www.tek-tips.com/viewthread.cfm?qid=1613334>
and
<https://www.youtube.com/watch?v=X_UaulmICtM&list=TLPQMTUwMjIwMjMRAYZJzCsXDQ&index=6>
specifically: at crystal report
TH1: Fomula fields/new/"nameabc"/enter/"Roman(GroupNumber)"/ ctrl+S/and pull it out
TH2: Fomula fields/new/"nameabc"/enter/
select GroupNumber
case 1 : " I"
case 2 : " II"
case 3 : " III"
case 4 : " IV"
case 5 : " V"
case 6 : " VI"
case 7 : " VII"
case 8 : "VIII"
case 9 : " IX"
case 10 : " X"
case 11 : " XI"
case 12 : " XII"
case 13 : "XIII"
case 14 : " XIV"
case 15 : " XV"
case 16 : " XVI"
case 17 : "XVII"
default : ""
/ ctrl+S/and pull it out
But it really doesn't help t so there will be this 3 case (t improved from link 2-3) it can apply to the 3rd or even 10th group of headings
TH3: ex: (you want to create a text message for group 3)
Formula fields/new/"nameabc"/enter/
"
WHILEPRINTINGRECORDS;
GLOBAL NUMBERVAR INTSTTGRTEST;
INTSTTGRTEST :=0;
/ ctrl+S/ drag it out and put it in heading group 2 and hide it (= right click/format field/common/ check Suppress/ok) you can go to link 3 to see
Formula fields/new/"nameabcd"/enter/
"
WHILEPRINTINGRECORDS;
GLOBAL numbervar INTSTTGRTEST := INTSTTGRTEST + 1;
stringvar y;
STRINGVAR ARRAY X := ["A","B","C","D","E","F","G","H","I","J","K", "L","M","N","O","P","Q","R","S","T","U","V","W","X ","Y","Z"];
if INTSTTGRTEST <= 26 then (
redim preserve X[INTSTTGRTEST];
y := X[INTSTTGRTEST]
);
y;
/ ctrl+S/and pull it out and place it at group 3
and the alphabet can be whatever we want. ex:
X := ["I","II","III","IV","V","VI","VII","VIII","IX","X","XI" ,"XII","XIII","XIV","XV","XVI","XVII","XVIII","XIX","XX","XXI","XXII","XXIII"," XXIV","XXV","XXVI","XXVII","XXVIII","XXIX","XXX","XXXI","XXXII","XXXIII","XXXIV","XXXV","XXXVI" ,"XXXVII","XXXVIII","XXXIX","XL","XLI","XLII","XLIII","XLIV","XLV","XLVI","XLVII","XLVIII"," XLIX","L"];
or
X := ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
hope it can help you
enter code here [1]: https://i.stack.imgur.com/OeBBQ.png

crystal reports : character "." in domain string errors

My goal is the discern whether the domain has a subdomain or not by counting the number of periods there are in the domain name. If it has 2 periods, there is obviously a subdomain.
I have the following crystal reports formula written in crystal syntax
local numbervar count :=0;
Local numbervar strLen := length({?domain});
local stringvar c := {?domain};
local numbervar i;
local numbervar pos2 :=0;
for i:=1 to strLen do
( if Mid({?domain}, i, 1) = "." then
(
count := count + 1;
if count = 2 then (
pos2 := i
);
);
);
if count > 1 then
left({?domain}, pos2)
else
left({?domain},instr({?domain}, ".")-1)
any ideas? hopefully this is something my tired eyes are just glazing over.
UPDATE: here is the weird thing that happens.
If I add "+ totext(pos2)
if count > 1 then
left({?domain}, pos2) + totext(pos2)
else
left({?domain},instr({?domain}, ".")-1)
it outputs correctly subdomain.domain with the .com removed
if i run it without the totext(pos2)
if count > 1 then
left({?domain}, pos2)
else
left({?domain},instr({?domain}, ".")-1)
it only shows the subdomain part of subdomain.domain.com
Any ideas why?
Should there be a final ; on the last line?
Alternatively, have you considered making the entire formula something like:
Left({?domain},InStrRev({?domain}, ".")-1)