How do I reset a string array variable - crystal-reports

I have a report with 4 different arrays.
All are set up like this
shared stringvar array arr1 := split({client_relations.sales_value}, "&");
'';
I need them to reset for each group. How do I do that? I tried something like this
WhilePrintingRecords;
shared stringvar array arr1 := " ";
But I got an error saying the formula could not create an array.

Someone suggested to me I try:
WhilePrintingRecords;
shared stringvar array arr1 := "";
'';
And it worked

Create a new formula putting the below code in, calling it reset or something along those lines and place it in the group header.
StringVar Array arr1;
Redim arr1[0];
However, you will have to put any outputs in the group footer for this to work as it resets all data at the start of a new group.

Related

MID of string results in empty value

I´m trying to convert values from database to text to get part of a string, but the result is always empty.
StringVar strCNPJ := CSTR({Command.numbers},10,"");
StringVar strResult;
strResult = MID(strCNPJ,1,3);
//strCNPJ
strResult
The result is:
Changing the variable result like this gets a string of numbers:
StringVar strCNPJ := CSTR({Command.CNPJDoFundo},10,"");
StringVar strResult;
strResult = MID(strCNPJ,1,3);
strCNPJ
//strResult
Is the problem with MID? Did I miss a parameter?
You missed one piece that I miss often.. you assign a variable using :=
so this line should read
strResult := MID(strCNPJ,1,3);

How to append a character in Crystal Report?

I am using CR version 13.0.2.000.I want to display the following Record
1,2,5,10,50,100
in the following way
$1
$2
$5
$10
$50
$100
I have tried the replace method and it successfully show the data columnwise but dont know how to append $ sign before the starting of each element
The formula i tried is given below
Replace({Table7.Value},",",chrw(10))
Keep in mind that you won't be able to use a formula to 'manufacture' rows; this will need to be done at the database.
If you just want to change the display, try:
// {#display}
Local Stringvar CRLF := Chr(10)+Chr(13);
// convert values to an array; 1,2,5,10,50,100
Stringvar Array tokens := Split({Table7.Value}, ",");
// join array
"$" + Join( tokens, CRLF + "$");
If you need to tally the array, try:
// {#aggregate}
Local Numbervar i;
Local Numbervar x;
// tally
for i := 1 to ubound(tokens) do (
x := x + ToNumber(tokens[i]);
);
// display
x
Try this solution. I tried by hardcoding strings and its worked for me.
WhilePrintingRecords;
Local StringVar Array x:=split({Table7.Value},",");
Local NumberVar i;
Local Stringvar y;
for i:=1 to Count(x) do
y:=y+"$"+x[i]+",";
Replace(y,",",chrw(13))

Format number formula

I have a number field in Crystal Report that must be shown in a specific format:
Eg:
12345678
must be shown as
1234-5678
I'm using a formula to transform the number to string, substring it 2 times and concatenate both values:
StringVar ordenT := Totext(GroupName ({DataTableInfCR.Orden}));
StringVar OrdenT1 := MID(ordenT,1,4);
StringVar OrdenT2 := MID(ordenT,4,4);
StringVar NroOrden := OrdenT1 +"-"+ OrdenT2;
However, the output for this code ends up being somthing like this:
12.3-45.6
I'm sure it because the default number format is with dots (ex: 12345678 will be 12.345.678)
How can I change the format via formula before my code??
Thanks!
To answer your question, to remove the decimals you use
StringVar ordenT := Totext(GroupName ({DataTableInfCR.Orden}),0);
or
StringVar ordenT := cStr(GroupName ({DataTableInfCR.Orden}),0);
EDIT:
See if this will take care of it all:
totext(GroupName({DataTableInfCR.Orden}),0,""),"xxxx-xxxx")

How to generate a Crystal Report from a list of parameters

My requirement is to generate a employee details report of multiple employees.Parameters for query will be employee number and a date range.
This is the record selection formula i'm using
{EMP_LEAVE_REPORT_VIEW.LEAVE_START_DATE} in {?sDate} to {?eDate}
and
(
Stringvar Array strings := Split({?empNoList}, "_");
Numbervar Array numbers;
Redim numbers[Ubound(strings)];
Numbervar i;
for i := 1 to Ubound(strings) do (
numbers[i] := ToNumber(strings[i]);
if {EMP_LEAVE_REPORT_VIEW.EMP_NO} = numbers[i] then
(true;)
else
(false;)
);
)
First i'm checking for the date.
Then i'm taking the employee list as a one string {?empNoList} eg: 5162_5468_5896_5236
and i'm splitting it to separate strings using "_" as the delimiter and assign those values again into a number array and using that value to filter the employee.
But this formula doesn't work.It gives the details of all the employees.
Is this a problem of the way i converted the string array or is there something wrong in the for loop of my code?
I used this code and tried assigning one employee number to the {?empNoList} and it worked.
if (ToNumber({?empNoList}) = {EMP_LEAVE_REPORT_VIEW.EMP_NO}) then true else false
Please help me out with this.Thanks in advance!
I found the solution!
Stringvar Array strings := Split({?empNoList}, "_"); //Spliting and saving the string in a string array
Numbervar Array numbers; //Creating a number array
Redim numbers[Ubound(strings)]; //Declaring number array size
Numbervar i;
//For loop to traverse through string and convert each into numbers and saving them in the numbers array
for i := 1 to Ubound(strings) do (
numbers[i] := ToNumber(strings[i]);
);
if({EMP_LEAVE_REPORT_VIEW.EMP_NO} in numbers) //If condition to check whether Employee number is in the numbers array
then
(true;)
else (false;)
It was a simple out of the box thinking ;)
1) Convert your EMP_LEAVE_REPORT_VIEW.EMP_NO to a string.
2) Then use the Like or In operator with {EMP_LEAVE_REPORT_VIEW.EMP_NO} and {?empNoList}
Simply, search the string version EMP_LEAVE_REPORT_VIEW.EMP_NO inside the bigger string {?empNoList}. You can avoid using the arrays.

error at runtime setting the size of an array in crystal reports

I've got 2 arrays;
shared stringvar array dkrowarrray;
shared stringvar array newArray;
I know that the first array contains 10 elements.
When I try to set the value of newArray I get a runtime error (Error in formula deltakrow: 'shared stringvar array dkrowarray; ' An array's dimension must be an integer between 1 and 1000). I'm trying to set it like;
numbervar dkrowarraysize := count(dkrowarray);//I also tried ubound here.
redim newArray[dkrowarraysize];
When I prescribe the value like redim newArray[10]; then it runs OK, but the size of the array will need to change.
Why does crystal not like the int variable name between the square brackets?
You misspelled dkrowarrray/dkrowarray. This worked for me:
shared stringvar array dkrowarrray := ["1","2","3","4","5"];
shared stringvar array newArray;
//5
ubound(dkrowarrray);
//0
ubound(newArray);
//3 ('rrr') lower-case 'r' characters in the name
numbervar dkrowarraysize := ubound(dkrowarrray);
//5
redim newArray[dkrowarraysize];
//5
ubound(newArray);