Help with If Else formula - crystal-reports

I want to run an if else on base of a commandfield on each row,
For example
If {CommandField=0} Update counter by 1 return counter
else if {CommandField=1} return 'Reporting'
I tried it but having error
stringVar layerType;
shared numberVar layNo;
if({Command.ISREPORT}=0) then
layNo:=layNo+1;layerType:=layNo;layerType
else if ({Command.ISREPORT}=1) then
layerType:='Reporting'; layerType
results should be like
ISREPORT LayerNo
0 1
0 2
0 3
0 4
1 'Reporter'

Not sure I understand but is this right:
stringVar layerType;
shared numberVar layNo;
if({Command.ISREPORT}=0) then
( layNo:=layNo+1;
layerType:=ToText(layNo);
layerType;
)
else
( if ({Command.ISREPORT}=1) then
layerType:='Reporting';
layerType
)
...which can be simplified to this:
shared numberVar layNo;
if({Command.ISREPORT}=0) then
(
layNo:=layNo+1;
ToText(layNo);
)
else
(if ({Command.ISREPORT}=1) then
'Reporting';)
..assuming the value of ISREPORT can only be 0 or 1 then we can further simplify to this:
shared numberVar layNo;
if({Command.ISREPORT}=0) then
(
layNo:=layNo+1;
ToText(layNo);
)
else
(
layNo:=0;
'Reporting';
)
Update - I've changed the last example to reset the counter on 'reporting'.
Edit:
change the ToText(.. to this ToText(layNo,0); (sets decimal places to zero)

Related

How to Print specific row in each page Crystal Report

whileprintingrecords;
global numbervar DetailCount;
DetailCount := DetailCount + 1;
Global numbervar DetailCount;
DetailCount Mod 10 = 0
IF Remainder (RecordNumber, 8) = 0 THEN
TRUE
ELSE
FALSE
IF Remainder (RecordNumber, 8) = 0 and not OnLastRecord THEN
TRUE
ELSE
FALSE
i have try this codes but not get it.
Please describe better what you would like to print on each page.
I'm guessing you would like to print a summary that would only show the sum of one printed page.
You need 3 formulas:
sum_pagesum (should be placed in the details-section as hidden field):
whileprintingrecords;
numbervar pagesum;
pagesum:= pagesum + {WHATEVER};
current_pagesum (should be placed in the page-footer-section, this prints your sum):
whileprintingrecords;
numbervar pagesum;
pagesum;
reset_pagesum (should be placed in the page-footer-section after the current_pagesum)
whileprintingrecords;
numbervar pagesum;
pagesum:= 0;

If Else text does not appear to be part of the formula

I am having trouble with if-else syntax. The error says the remaining text does not appear to be part of the formula. How can I resolve this?
NumberVar k:={#Counting_Data}/{#Counting_Fail}
if k > 2 then
StringVar l:="Failed"
else if k <= 2 and k>0
StringVar l:="Promoted"
else if k = 0 then
StringVar l:="Passed"
else ""
NumberVar k:={#Counting_Data}/{#Counting_Fail};
if k > 2 then
StringVar l:="Failed"
else if k <= 2 and k>0 then
l:="Promoted"
else if k = 0 then
l:="Passed"
else ""

crystal report: print missing records

i want to print missing records in crystal report .
i am using below formula in the report and i have placed this formula in details b section.
details a has normal report fields.
formula:
local numbervar firstemp; // first Emp#
local numbervar nextemp; // next Emp#
local numbervar diff; // difference between firstemp and nextemp
local numbervar increase; // increment for missing Emp#'s
local numbervar result;
increase := 0;
firstemp := tonumber({getRptSalesSummery;1.Bill_Id});
nextemp := tonumber(next({getRptSalesSummery;1.Bill_Id}));
nextemp := nextemp -1;
diff := nextemp - firstemp;
if nextemp = firstemp
then ""
else (
while diff >= 1
do (
diff := diff - 1;
increase := increase + 1;
result := firstemp + increase;
exit while;
);
totext (result,"0000") & chr(13);
)
this formula is not giving me range.
for example if in report there is range of 1 to 10 and 6,7,8,9 is missing records, then if i check in the report its printing 1 to 5 and 6 as missing then directly 10, but its not giving me 7,8,9.
basically i required range of missing records

How to find occurances of a string in crystal report?

I am trying to count the total number of (First column closed) Closed records. But I Get the result like 1.00 and 0.00 .
Desired results:
Code:
Local NumberVar str := 0;
Local NumberVar strLen := count({#Status});
Local NumberVar i;
For i := 1 To strLen Do (
If instr(i, {#Status}, "Closed") <> 0 Then
str := str + 1;
);
If(str > 0 ) Then str
You have two obvious options:
1) Running total with a evaluation expression: instr({#Status}, "Closed") <> 0 set to count
2) Create a new formula if instr({#Status}, "Closed") <> 0 then 1 else 0 then you can summarize that (either in a formula or using a "summary")
Your formula should be:
// formula's result might not always be 'Closed'
IIf( InStr({#Status}, "Closed") > 0, 1, 0 )
or
// formula's result is clean
IIf( {#Status}="Closed", 1, 0 )
** edit **
Insert a summary field that references this formula. By the way, this formula doesn't need to be added to the canvas to function correctly.

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;