I need a way to extract a numeric value from an alphanumeric one, for example :
3 MS 15 SEC
Desired:
3.15
Try:
Local NumberVar i;
Local StringVar k;
for i:=1 to Count (Split("3 MS 15 SEC"," ")) do
(
if NumericText (Split("3 MS 15 SEC "," ")[i]) then (
k:=k+Split("3 MS 15 SEC "," ")[i]+".";
)
);
if k<>"" then
k[1 to length(k)-1]
else
k //drop final "."
Try:
// {#extract}
Local Stringvar Array tokens:=Split(x);
Local Stringvar Array values;
Local Numbervar i;
for i := 1 to uBound(tokens) do (
if isNumeric(tokens[i]) then (
redim preserve values[ubound(values)+1];
values[ubound(values)]:=tokens[i];
)
);
ToNumber( Join(values,".") );
Related
in my report some of data will show as below:
MY22000940 / 020 /000
how can i make the words become
020 / 000
only if the 1st 2 character start with MY ?
Try this logic:
local stringvar MyString := "MY22000940 / 020 /000";
If Left(MyString, 2) = "MY" Then
(
local numbervar slash_position := instr(MyString, "/");
Right(MyString, Len(MyString) - (slash_position + 1));
)
ELSE MyString;
I'm a noob in Crystal Report.
I'm getting String length is less than 0 or not an integer error.
on left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1)
of the code below:
local StringVar mDate;
local StringVar mMonth;
local StringVar mDay;
local StringVar mYear;
if {ORDERCHECKVIEW.LOTNUMBER} = 'N/A'
then 'N/A'
else
mDate:= left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1);
mMonth:= left(mDate,2);
mDay := Mid (mDate,4 ,2 );
mYear := totext(2010 + CDbl (right(mDate,InStr(StrReverse(left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1)),"-") -1 )),0,""); // transform 2017
cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay));
cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay));
Can anyone please explain what's wrong? I don't think my if-else statement is wrong..
FYI, I have previously asked a question and this question is a follow-up:
(Advanced conversion of a single number to year, along with hyphen)
compounded if-else
local StringVar mDate;
local StringVar mMonth;
local StringVar mDay;
local StringVar mYear;
if {ORDERCHECKVIEW.LOTNUMBER} = "N/A"
then "N/A"
else
(
mDate:= left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1);
mMonth:= left(mDate,2);
mDay := Mid (mDate,4 ,2 );
mYear := totext(2010 + CDbl (right(mDate,InStr(StrReverse(left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1)),"-") -1 )),0,""); // transform 2017
// cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay));
ToText(cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay)),"MM/dd/yyyy") ;
)
I am using Crystal Reports 2013 SP5 on Windows 7 Pro pulling from an Oracle db.
I am trying to write a formula(s) in crystal reports that returns the total number of days the remaining hours if less than 24, and the remaining minutes if less than 60 from a datediff between two date time fields.
So far I have managed to show the total number of minutes as days, hours, and minutes:
local numbervar tm := datediff('n',{table.date1},{table.date2},0);
local numbervar h := truncate(tm/60,0);
local numbervar d := truncate(tm/1440,0);
local stringvar tm_d := totext(d,0,"") + ' days ';
local stringvar tm_h := totext(h,0,"") + ' hours ';
local stringvar tm_m := totext(tm,0,"") + ' minutes ';
local stringvar tm_string := tm_d & tm_h & tm_m
Returns: 183 days 4393 hours 263633 minutes
183 days which is = to 4393 hours which is = to 263633 minutes
What I need it to do is show 183 days (not rounded) and any remaining hours (not rounded) and any remaining minutes (not rounded) so it looks something like this:
The difference between table.date1 and table.date2 is:
183 days 4 hours 23 minutes (just used random hours and minutes)
Just try this also.
local numbervar tt := datediff('n',{table.DATE1},{table.DATE2});
local numbervar d := truncate(tt/1440,0);
local numbervar h := truncate(remainder(tt,1440)/60,0);
local numbervar m := truncate(remainder(tt,60),0);
local stringvar tt_d := if d=0 then "" else totext(d,0,"") + 'd ';
local stringvar tt_h := if h = 0 then "" else (totext(h,0,"")) + 'h ';
local stringvar tt_m := totext(m,0,"") + 'm ';
local stringvar tt_string := tt_d & tt_h & tt_m
Refer links :
http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=15879
http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=10279
http://www.experts-exchange.com/Database/Reporting/Crystal_Reports/Q_24014196.html
Have no experience with your system, but definitely you'll need this:
totalMinutes = 263633
days = floor (totalMinutes /(24*60))
hours = floor (totalMinutes %(24 * 60) /(60))
minutes = floor (totalMinutes % 60)
where % is MOD (ex: 15 MOD 4 = 3)
as far as I see, floor is same as truncate, and quick lookup gave, that MOD is MOD like A MOD B
i want to print missing records in crystal report .
i am using below formula in the report and i have placed this formula in details b section.
details a has normal report fields.
formula:
local numbervar firstemp; // first Emp#
local numbervar nextemp; // next Emp#
local numbervar diff; // difference between firstemp and nextemp
local numbervar increase; // increment for missing Emp#'s
local numbervar result;
increase := 0;
firstemp := tonumber({getRptSalesSummery;1.Bill_Id});
nextemp := tonumber(next({getRptSalesSummery;1.Bill_Id}));
nextemp := nextemp -1;
diff := nextemp - firstemp;
if nextemp = firstemp
then ""
else (
while diff >= 1
do (
diff := diff - 1;
increase := increase + 1;
result := firstemp + increase;
exit while;
);
totext (result,"0000") & chr(13);
)
this formula is not giving me range.
for example if in report there is range of 1 to 10 and 6,7,8,9 is missing records, then if i check in the report its printing 1 to 5 and 6 as missing then directly 10, but its not giving me 7,8,9.
basically i required range of missing records
Let assume
x = 1001
Now I am inputting x to my code and generating y in the following order:
Length of 1001 is 4 so starting from the last number
i.e. 1(number) * 4(position of number) & 0 * 3 & 0 * 2 & 1 * 1 that gives a new number 4001
Another eg. 1234 gives 16941
In crystal I am creating a formual as follows:
stringvar tmp_EventNo;
stringvar tmp_Password;
numbervar i;
numbervar m_password;
tmp_EventNo = Trim(ToText({GR_EVENT.event_number}));
For i := Len(tmp_EventNo) To 1 Step -1 Do
(
tmp_PassWord = tmp_PassWord & Trim(ToText(Val(Mid(tmp_EventNo, i, 1)) + i));
);
m_Password = Val(tmp_PassWord);
m_password
But it doesnt seem to work. Just results in 0.00
Please help thanks in advance
Nice easy one- you will kick yourself :)
In Crystal = is used for evaluation. := is used for assignment.]
There were a few other issues with the code so i tweaked it for you:
stringvar tmp_EventNo;
stringvar tmp_Password;
numbervar i;
numbervar m_password;
tmp_EventNo := Trim(ToText({GR_EVENT.event_number}, 0, ''));
For i := Len(tmp_EventNo) To 1 Step -1 Do
(
tmp_PassWord := tmp_PassWord & Trim(ToText(Val(Mid(tmp_EventNo, i, 1)) * i,0));
);
m_Password := Val(tmp_PassWord);
tmp_PassWord;