I have a field like this, where I only want the first/latest entry to show on the Crystal report:
05/01/2018 00:00:00 pm notes
04/01/2018 00:00:00 pm more notes
03/01/2018 00:00:00 pm even more notes
Here's the code I have been trying to work with, but I get an error of "a subscript must be between 1 and the size of the array." Can someone please help point me in the right direction?
stringvar array csl;
stringvar return;
csl:=split({table.field},chr(13));
//csl[1]
if isnull({table.field}) then return:= ""
else return:=csl[1];
return;
The reason for the error is presumably because the check for null happens after the split.
I usually try to avoid using arrays/variables in Crystal Reports. Mainly because you can't group or use aggregate functions on formulas that contain variables.
So here's a solution that works with string-functions:
First Entry
If InStr({table.field}, chr(13)) > 0 Then
Left({table.field}, InStr({table.field}, chr(13)))
Else
{table.field}
Last Entry
If InStrRev({table.field}, chr(13)) > 0 Then
Right({table.field}, Len({table.field}) - InStrRev({table.field}, chr(13)))
Else
{table.field}
EDIT
To get the second line too you have to do the InStr/InStrRev two times:
First Entry
If InStr(InStr({#table.field}, chr(13))+1,{#table.field}, chr(13)) > 0 Then
Left({#table.field}, InStr(InStr({#table.field}, chr(13))+1, {#table.field}, chr(13)))
Else
{#table.field}
Last Entry
If InStrRev({#table.field}, chr(13), InStrRev({#table.field}, chr(13))+1) > 0 Then
Right({#table.field}, Len({#table.field}) - InStrRev({#table.field}, chr(13),InStrRev({#table.field}, chr(13))-1))
Else
{#table.field}
Related
I'm new to crystal so please excuse me if this is a stupid question. I've got a database field in Sage ERP which is the time, stored as a GMT time, the field type is number. So for example the data in the filed will be 8461110 (08:46) or 13021054 (13:02). Now in crystal I need to convert this field to time because I need to select data between 2 times. I've struggled with this yesterday for the whole time, but no luck.
I've created a formula field with the following code but the result I get is 00:00:00
Local NumberVar TheHour;
Local NumberVar TheMin;
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheHour = ToNumber(Left(ToText({ICHIST.AUDTTIME}),2))
else
TheHour = ToNumber(Left(ToText({ICHIST.AUDTTIME}),1));
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheMin = ToNumber(Mid(ToText({ICHIST.AUDTTIME}),3,2))
else
TheMin = ToNumber(Mid(ToText({ICHIST.AUDTTIME}),2,2));
Time(TheHour,TheMin,00);
What am I doing wrong, why is the result 00:00:00?
Problem is you are missing this :. In crysal reports whenever you want to assign a value to a variable syntax would be :=. So your formula will be
Local NumberVar TheHour;
Local NumberVar TheMin;
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheHour := ToNumber(Left(ToText({ICHIST.AUDTTIME}),2))
else
TheHour := ToNumber(Left(ToText({ICHIST.AUDTTIME}),1));
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheMin := ToNumber(Mid(ToText({ICHIST.AUDTTIME}),3,2))
else
TheMin := ToNumber(Mid(ToText({ICHIST.AUDTTIME}),2,2));
Time(TheHour,TheMin,00);
I have a report that has multiple 0 values, but instead of showing the zero, crystal shows a blank space instead. then, 2 columns over i have a field that should subtract another field from that 0 and be negative, but since the zero field is empty, it wont and the difference comes up empty two. Any idea how to fix this?
this is my code snippet for the field that has the zero:
if {fullmain.initres} > 0
then {fullmain.initres}
else 0.00
this is my code snippet for the field that should show the difference :
if {#RESERVE} > 0 then
{#RESERVE}-{#AMOUNT}
else 0 - {#AMOUNT}
place the field({fullmain.initres} and {#RESERVE}) right next to your formula and check if it is returning a null value, in this case blank. If so you might need to add and or to your if statement saying
if isnull({fullmain.initres} <= 0 or {fullmain.initres})
then 0.00
else {fullmain.initres}
if isnull({#RESERVE} or {#RESERVE} <= 0)
then 0 - {#AMOUNT}
else {#RESERVE}-{#AMOUNT}
I need a formula like this:
if {#TarSale_TimeWise}= 0 or isnull({#TarSale_TimeWise}) then '-'
else
totext(round(({#ActSale_TimeWise}-{#TarSale_TimeWise})/{#TarSale_TimeWise}*100,1),1)
Here the formula for {#TarSale_TimeWise} is
round({CatTimeWise.tarSale},1)
Similarly the formula for {#ActSale_TimeWise} is
round({CatTimeWise.ActSale},1)
I need to take rounding as 1 for both the fields and then I need to do the calculation for var sale with values round as 1 for both the formulas.
Now instead of creating this below 2 formulas and using those in 3rd formula I want to create only one formula using variables.
How can I modify above formulas as 1 formula?
Create only one formula and write below code:
Local Numbervar a1:=round({CatTimeWise.tarSale},1) ;
Local NumberVar a2:=round({CatTimeWise.ActSale},1) ;
if a1= 0 or isnull(a1) then '-'
else
totext(round((a2-a1)/a1*100,1),1)
Try:
If Isnull({CatTimeWise.tarSale}) Or {CatTimeWise.tarSale}=0 Then
'-'
Else
ToText( Round( (({CatTimeWise.ActSale} - {CatTimeWise.tarSale}) / {CatTimeWise.tarSale}*100), 1), 1 )
I have created a crystal report which groups products based on order number.
I have created a formula which displays the text 'Partially Completed' or 'Fully Completed' based on whether a field on each product called 'Difference' equals 0 or not. If 'Difference' is 0 then 'Fully Completed' is displayed and vice-versa.
What I need to do is to display the corresponding message for the overall order number (i.e. if any of the products for an order have a difference != 0 then display 'Partially Completed'. If all the products have a difference == 0 for an order then display 'Fully Completed'.
This is the code I have attempted so far:
StringVar ouputText;
if {AD_999_SB_Fulfillment__Summary.FulfillmentPicking.Difference} = 0 then
ouputText := 'Full'
else
ouputText := 'Partial';
ouputText;
I assume I need some kind of for-loop to loop through all of the products for an order and check to see if any of the orders have a difference != 0 and then update the message based on if all the products have a difference == 0 or one of the products breaks the condition by having a difference != 0.
Looping is a lenghty process instead you group your report according to the "Order" then place the product in detail part. This will automatically loop entire products in a Order.
Create formula with name reset and place it in group header. Code is below.
Shared stringVar array y;
y:=" ";
join(y);
Create a formula and place it in detail section. This will take the result and store it in array for future use. Use below code.
StringVar ouputText;
Shared stringVar array y;
if {AD_999_SB_Fulfillment__Summary.FulfillmentPicking.Difference} = 0 then
y:= y+'Full'
else
y:= y+'Partial';
if {AD_999_SB_Fulfillment__Summary.FulfillmentPicking.Difference} = 0 then
ouputText := 'Full'
else
ouputText := 'Partial';
ouputText;
In group footer create another formula to display whether result is full or partial for order.
Shared stringVar array y;
if "Partial" in y
Then "partial"
else "Full";
I'm trying to compare two fields that contain up to 2 digit field.
One formula field is a {string} the other to compare to is a {number} field.
But i"m running to a problem when the string field shows for example "08" and the number field shows "8" then it will show 1 that there is a differences but actually there is no difference. If the string field shows 14 and the number field shows 14 that works perfectly but anything between 1-9 will show a difference when actually there is no difference.
This is what I tried so far.
If {number.field} = 0
Then StringVar AdjustValue:= " "
Else StringVar AdjustValue:= totext ({number.field},0,"")
;
if {#stringfield} = StringVar AdjustValue then 0 else 1
Thanks in advance for the help.
Instead, convert from string to numeric so you don't have to worry about leading zeros.
if tonumber({#stringfield})={number.field} then 0 else 1
And just a quick side note: You are re-declaring the AdjustValue variable three times. There's no need to refer to it via "StringVar" after an initial variable declaration within the same formula.
EDIT: Since you're having problems with the top formula, you could also try the alternative of just padding your AdjustValue variable to two spaces:
stringvar AdjustValue;
If {number.field} = 0
Then AdjustValue:= " "
Else AdjustValue:= totext ({number.field},"00") //add padding
;
if {#stringfield} = StringVar AdjustValue then 0 else 1
Keep it simple with a formula field that will return a Boolean value:
// {#compare}
ToNumber({#string})={number.field}
Reference the {#compare} where ever you need it.