If On First record take filed else sum varible numberVar in crystal report - crystal-reports

So i am working on report in crystal report and i have some problem
i have filed name opening that come from database
i have numberVar in the formula so
if on first record to sum numberVar =(opening +INqty - Outqty)
else numberVar +INqty - Outqty
and i want for every item
but what happen is when the information on the first item end it take the last sum of numberVar and sum to it the second item
this is my formlua :
numberVar BALQTY;
IF OnFirstRecord THEN
BALQTY := 0 ;
IF OnFirstRecord THEN
BALQTY := {stockCard;1.open1}+{stockCard;1.InQty}-{stockCard;1.outQty}
ELSE
BALQTY := BALQTY + {stockCard;1.InQty} -{stockCard;1.outQty} ;
any help plz

According to your explanation, looks like you need to run for every record separately and your variable is retaining the previous item value, this is because of incorrect variable declaration
You have declared the variable with Global scope instead create a variable with Local scope.
Change numberVar BALQTY; to Local numberVar BALQTY;

Related

Crystal Reports, not getting a value out of my formula to display in the report field

I have records coming in to my report that contain fields "masterTypeId" and "amount". In my report footer I have an String field "#UnboundString30". The formula is:
(Local NumberVar r;
r := 0;
WhileReadingRecords;
if{Table.masterTypeId}=2
then r := r + {Table.amount})
The Formula Workshop will save and close. When I run the report #UnboundString30 is always 0 despite there being many masterTypeIds of 2 and many amounts. It appears to me that I need to tell my field that it should be the value of r but I don't know how to do that?
Thanks!
It looks like you are missing the return. Try to add on line, like this:
Local NumberVar r;
r := 0;
WhileReadingRecords;
if{Table.masterTypeId}=2
then r := r + {Table.amount};
r; //this is the return

Sequence no in crystal report XI while duplicate row find in record

whileprintingrecords;
Global numbervar var;
if (({USP_ExCombWeaponAmmunitionList;1.RegistrationNo}) =
previous({USP_ExCombWeaponAmmunitionList;1.RegistrationNo})) then
var := var
else
var := var+1;
Why above code skip first row sequence no blank and started from second row by sequence 1?
The formula silently "crashes" as there is no previous record before the first record.
One possibility is to foremost check if the current record is the first record by using OnFirstRecord.
In this case assign 1 to var.
whileprintingrecords;
Global numbervar var;
if OnFirstRecord then
var := 1
else if (({USP_ExCombWeaponAmmunitionList;1.RegistrationNo}) =
previous({USP_ExCombWeaponAmmunitionList;1.RegistrationNo})) then
var
else
var := var+1;
BTW one can write var instead of var := var, as this is just a unnecessary reassignment of the variable.

Add formula in if else statement

I need a formula in a display string to change the text in a crosstab. I have to calculate some numeric value based database values and replace some values with "". Below is the formula for numeric values:
shared numberVar array sgpa;
shared stringVar array stds;
shared booleanVar array show_gpa;
numberVar i;
stringVar _sgpa:="";
for i:=1 to count(stds)
do
if stds[i] = GridRowColumnValue("TAB_COURSE_GRADE.STD_ID2") then _sgpa :=
iif(show_gpa[i], ToText(sgpa[i],"##.##"),"");
_sgpa
How can I effectively add this if/else statement when it otherwise gives me "A string is required here" errors:
shared numberVar array sgpa;
shared numberVar array sgpa;
shared stringVar array stds;
shared booleanVar array show_gpa;
numberVar i;
stringVar _sgpa:="";
If CurrentFieldValue = "UF"
Then ""
Else
for i:=1 to count(stds)
do
if stds[i] = GridRowColumnValue("TAB_COURSE_GRADE.STD_ID2") then _sgpa := iif(show_gpa[i], ToText(sgpa[i],"##.##"),"");
_sgpa
Why not separate it into multiple formulas?
Make an individual formula Calculations which will perform all the math necessary to get the display value, but doesn't do the CurrentFieldValue check. Then make a second formula called IfElse which will look something like:
IF CurrentFieldValue = "UF" THEN "" ELSE CSTR({#Calculations})

Crystal Reports 2013 Why isn't my variable incrementing

In the Group Header I place a variable with this formula:
Global NumberVar NumZika := 0;
In the details section I place a variable with this formula:
Global NumberVar NumZika := Global NumberVar NumZika + 1 ;
It never increments past 1.00 (see screenshot below)
Thanks in advance
Do it like this:
Global NumberVar NumZika:=0;
NumZika:=tonumber(NumZika)+ 1;
Initialize in the header section:
Global NumberVar NumZika:=0;
Increment in the details section:
WhilePrintingRecords;
Global NumberVar NumZika:= Global NumberVar NumZika+ 1
Display value in the footer:
WhilePrintingRecords;
Global NumberVar NumZika;

For loops in Crystal Reports 2008

I'm trying to perform a very basic depreciation calculation based on the age of an asset using a For loop in Crystal 2008, and cannot get it working for the life of me.
The loop looks like this:
NumberVar AssetValue := {CIID.Currency4};
NumberVar DepreciationPercentage := {vw_DepreciationValues.Percent};
NumberVar AssetAge := DateDiff("yyyy",{CIID.Date4},CurrentDate);
Numbervar i := 0;
for i := 0 to AssetAge do
(
AssetValue = AssetValue - ((AssetValue/100)*DepreciationPercentage);
i = i + 1;
);
AssetValue;
For some reason, it always outputs AssetValue as the same number that went in....almost like it gets reset after being run.
I've tested the depreciation formula outside of the loop, and it works fine.
I've also verified that the i counter is getting incremented properly by the loop.
Anyone got a clue as to where I'm going wrong? I've even tried creating a custom function using private variables, but it made no difference.
Thanks in advance!
Typos:
AssetValue = AssetValue - ((AssetValue/100)*DepreciationPercentage);
^--- equality test
i = i + 1
^-- ditto
it should be := to do an assignment.