remove 1st word in crystal report variables - crystal-reports

in my report some of data will show as below:
MY22000940 / 020 /000
how can i make the words become
020 / 000
only if the 1st 2 character start with MY ?

Try this logic:
local stringvar MyString := "MY22000940 / 020 /000";
If Left(MyString, 2) = "MY" Then
(
local numbervar slash_position := instr(MyString, "/");
Right(MyString, Len(MyString) - (slash_position + 1));
)
ELSE MyString;

Related

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,".") );

Converting numbers to MM:SS format in Cross-tab

I'm trying to convert a value in Cross-tab of Crystal report into a MM:SS format. I used the following steps: Right-click summary > Format Field > Display String > x+2
WhilePrintingRecords;
NumberVar curr := CurrentFieldValue;
NumberVar mins := Truncate(curr / 60);
NumberVar secs := Remainder(curr, 60);
ToText(mins, 0, "") & ":" & ToText(secs, 0, "")
The results are ok when the secs is not 0. Example: `4:30'
But, I am having problems when secs is 0, the result is (for 4 minutes): 4:0
I would like to have the output as 4:00, with the seconds display as always a 2 digit number.
Thank you for all your help
You my ElapsedTime function in conditional-formatting expression.
I used this instead, and it worked :)
NumberVar curr := CurrentFieldValue;
NumberVar mins := Truncate(curr / 60);
NumberVar secs := Remainder(curr, 60);
ToText(mins, 0, "") & ":" & ToText(secs, '00')

Crystal Reports Formula to generate a random number

Let assume
x = 1001
Now I am inputting x to my code and generating y in the following order:
Length of 1001 is 4 so starting from the last number
i.e. 1(number) * 4(position of number) & 0 * 3 & 0 * 2 & 1 * 1 that gives a new number 4001
Another eg. 1234 gives 16941
In crystal I am creating a formual as follows:
stringvar tmp_EventNo;
stringvar tmp_Password;
numbervar i;
numbervar m_password;
tmp_EventNo = Trim(ToText({GR_EVENT.event_number}));
For i := Len(tmp_EventNo) To 1 Step -1 Do
(
tmp_PassWord = tmp_PassWord & Trim(ToText(Val(Mid(tmp_EventNo, i, 1)) + i));
);
m_Password = Val(tmp_PassWord);
m_password
But it doesnt seem to work. Just results in 0.00
Please help thanks in advance
Nice easy one- you will kick yourself :)
In Crystal = is used for evaluation. := is used for assignment.]
There were a few other issues with the code so i tweaked it for you:
stringvar tmp_EventNo;
stringvar tmp_Password;
numbervar i;
numbervar m_password;
tmp_EventNo := Trim(ToText({GR_EVENT.event_number}, 0, ''));
For i := Len(tmp_EventNo) To 1 Step -1 Do
(
tmp_PassWord := tmp_PassWord & Trim(ToText(Val(Mid(tmp_EventNo, i, 1)) * i,0));
);
m_Password := Val(tmp_PassWord);
tmp_PassWord;

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)