A month number must be between 1 and 12, Error<Month> - crystal-reports

Error in formula .
'Stringvar Array strings := Split({?#V2_month}, ",");'
A month number must be between 1 and 12.
Above is the error that i get, {?#V2_month} is my report parameter.
Month is my formula field
Below is the formula in the Month formula field
Stringvar Array strings := Split({?#V2_month}, ",");
Stringvar result := "" ;
//populate array
Numbervar i;
for i := 1 to Ubound(strings)
do (
result := result + MonthName(ToNumber(strings[i]) , true)+", " ;
);
MID(result , 1 , len(result) - 2);
Any idea why this formula prompt this kind of error?

I got the same error as yours. You forgot to add comma in your input values of the parameter ?#V2_month making it more than 12 or less than 1. Make sure the value you entered is comma separated and number between 1 and 12.

Related

How to split data every n-th character and make it into array in crystal report

i want to split data to make it into array. so given for example: 12345678
i want to get string array like this => ["234","678"]
is it possible in crystal report?
Yes, it is possible. But the requirements are not clear.
Data type of input (string or Number?)
Logic: discard 1st character? Then, groups of 3 skipping the 4th character?
Here is formula code that takes "12345678" and returns "^234^678":
local stringvar myString := "12345678";
local stringvar myDelimitedString := "";
local numbervar StringLength := Len(myString);
local numbervar i;
For i := 1 to StringLength step 4 do
myDelimitedString := myDelimitedString + "^" + MID(myString, i+ 1, 3);
myDelimitedString;

mask a field with no fixed length in crystal reports 2008

I have a field in crystal reports that displays customer's names. the requirement however is to just display the first 5 characters, which includes spacing as well. whatever comes after the 5th character will be converted into * and the spacing shall be displayed as a space still. as the name field varies, how do i accomplish this?
currently i only have this, which displays the first 5 characters and replaces only the 6th character with an *
Replace({Command.CUST_NAME},MID({Command.CUST_NAME},6),"*")
Unfortunately, it seems Crystal does not suport regex.
So, i would do a function. Try this:
stringvar input := {Command.CUST_NAME};
stringvar output := MID(input, 1, 5);
numbervar i;
for i:=5 to Length (input) step 1 do (
stringvar aChar := MID(input, i, 1);
if aChar <> " " then aChar := "*";
output := output + aChar;
);
output
Maybe you will have to handle if {Command.CUST_NAME} is smaller than 5 chars.

Crystal Report formula issue :How to split multi line text value in to the array and how to fetch it by forloop in

I have one field in a dataset which has a multi-line textbox value. I want to split that record, store it into an array, and when I fetch the value from the array by a for-loop, I want to prepend a "*" to each line. I have written a formula for that but it's working only for 2 values. After that it's not working and I'm not able to get how to retrieve the value like this.
I want the result to be:
* 123
* 234
* 786
But I'm getting the result:
*123
234
786
my formula is
Local StringVar y;
Local StringVar x;
Local NumberVar i;
y := ""+ chrw(10);
x := y;
Stringvar Array strings := Split({Touche.Concerns}, "\r\n");
Stringvar Array numbers;
For i :=1 To Ubound(strings) Do
(
y := y + chrw(10)+ "$" + strings[i];
);
y;
Instead of a long formula which breaks into arrays and manipulates each line, why not just replace the line breaks with a line break and the asterisk?
"* " & replace(trim({Touche.Concerns}), "\r\n", "\r\n* ");
The leading '*' is to place the char on the first line and the trim function is called to remove any trailing line breaks (so there won't be a line with just the asterisk).
As a side note, use & when concatenating strings and not the + char. Use the + can sometimes cause coercion to where numeric values would be added together. For example "12" + "34" would yield 46 instead of 1234. The & char ensures string concatenation is used.

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.

Number to String in a formula field

I am using a formula field to concatonate 2 decimal values separated by a dash. However, I want the result to trim all unneccesary trailing zeros and decimal points for both values.
For example, I want values 10 and 8.5 to be "10 - 8.5". Now it shows "10.00 - 8.50".
The formula I am using is CSTR({field1}) + " - " + CSTR({field2}).
I believe this is what you're looking for:
Convert Decimal Numbers to Text showing only the non-zero decimals
Especially this line might be helpful:
StringVar text := Totext ( {Your.NumberField} , 6 , "" ) ;
The first parameter is the decimal to be converted, the second parameter is the number of decimal places and the third parameter is the separator for thousands/millions etc.
CSTR({number_field}, 0, '')
The second placeholder is for decimals.
The last placeholder is for thousands separator.
i wrote a simple function for this:
Function (stringVar param)
(
Local stringVar oneChar := '0';
Local numberVar strLen := Length(param);
Local numberVar index := strLen;
oneChar = param[strLen];
while index > 0 and oneChar = '0' do
(
oneChar := param[index];
index := index - 1;
);
Left(param , index + 1);
)