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);
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 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
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")
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);