I need to convert a string to time. What would be a good way to do this? Some fields are correct, but we are finding some without the :.
"093420" to "09:34:20"
I have tried(not working):
stringvar _time:={some time field};
stringvar _ftime:=_time;
if instr(_time,':') = 0 then
_ftime = mid(_time,1,2)+":"+mid(_time,3,2)+":"+mid(_time,5,2);
_ftime
You've got a bug... you're not using the assignment operator on line 4. Your code should read:
stringvar _time:={some time field};
stringvar _ftime:=_time;
if instr(_time,':') = 0 then
_ftime := mid(_time,1,2)+":"+mid(_time,3,2)+":"+mid(_time,5,2); //assignment op
_ftime
Related
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;
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.
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);
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")
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.