I'm new to crystal so please excuse me if this is a stupid question. I've got a database field in Sage ERP which is the time, stored as a GMT time, the field type is number. So for example the data in the filed will be 8461110 (08:46) or 13021054 (13:02). Now in crystal I need to convert this field to time because I need to select data between 2 times. I've struggled with this yesterday for the whole time, but no luck.
I've created a formula field with the following code but the result I get is 00:00:00
Local NumberVar TheHour;
Local NumberVar TheMin;
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheHour = ToNumber(Left(ToText({ICHIST.AUDTTIME}),2))
else
TheHour = ToNumber(Left(ToText({ICHIST.AUDTTIME}),1));
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheMin = ToNumber(Mid(ToText({ICHIST.AUDTTIME}),3,2))
else
TheMin = ToNumber(Mid(ToText({ICHIST.AUDTTIME}),2,2));
Time(TheHour,TheMin,00);
What am I doing wrong, why is the result 00:00:00?
Problem is you are missing this :. In crysal reports whenever you want to assign a value to a variable syntax would be :=. So your formula will be
Local NumberVar TheHour;
Local NumberVar TheMin;
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheHour := ToNumber(Left(ToText({ICHIST.AUDTTIME}),2))
else
TheHour := ToNumber(Left(ToText({ICHIST.AUDTTIME}),1));
If Len(ToText({ICHIST.AUDTTIME})) = 8 Then
TheMin := ToNumber(Mid(ToText({ICHIST.AUDTTIME}),3,2))
else
TheMin := ToNumber(Mid(ToText({ICHIST.AUDTTIME}),2,2));
Time(TheHour,TheMin,00);
Related
I've been searching your questions for a while, finding the answers to many of my own. But I can't find any help with these:
1-We recently migrated to Windows 10, and following that there are a few reports that work just fine for my coworker but not me. Most of our reports work fine either way. So far as we can tell, we have the same setup, same drivers, same ODBC connections, same versions, everything. Only I get no data, and he gets data. I don't get any error messages, just the report returns with all 0s when we know there is data to find.
2-Also, we have reports that pull from Outlook folders which also no longer work. We are getting a "non-numeric string" error for a field that returns a date and did not throw any errors before the migration. We are only able to return data from before the migration. When running those reports from a Windows 7 machine, we get the same issues plus a MAPI error pop up.
For the affected reports, I have re-built them from scratch on the Win 10 machine to no avail. We are scratching our heads about this, and think it has to be something on the backend that we don't have access to, but not sure what to bring up to the Sys Admin for resolution. Any advice would be greatly appreciated!
Formula with non-numeric string error (formula previously worked without issue):
whileprintingrecords;
shared stringvar Monthpart;
shared numbervar Monthnum;
shared stringvar daypart;
shared numbervar daynum;
shared stringvar Yearpart;
shared numbervar yearnum;
shared numbervar hournum;
shared stringvar hourpart;
shared numbervar minpart;
shared numbervar IdPmAm;
shared datetimevar date2;
//Parse out data
Monthpart := {#Date}[1 to 2];
daypart := ToText({#Date}[4 to 5]);
Yearpart := ToText({#Date}[7 to 10]);
If (Instr({#Date},":")-Instr({#Date}," ")) = 3 then
(hournum := tonumber({#Date}[12 to 13]);
Minpart := tonumber({#Date}[(Instr({#Date},":")+1) to (Instr({#Date},":")+2)]))
else if (Instr({#Date},":")-Instr({#Date}," ")) = 2 then
(hournum := tonumber({#Date}[12]);
Minpart := Tonumber({#Date}[(Instr({#Date},":")+1) to (Instr({#Date},":")+2)]))
else if (Instr({#Date},":")-Instr({#Date}," ")) = 0 then
(hournum := 0;
Minpart := 0;);
IdPmAm :=(Instr({#Date}, ":")+ 4);
If ({#Date}[IdPmAm] = "P" and hournum <> 12) then
hournum := hournum + 12;
//Change data to numbers
If NumericText(MonthPart) then Monthnum := tonumber(Monthpart);
If NumericText(DayPart) then Daynum := tonumber(Daypart);
If NumericText(YearPart) then yearnum := tonumber(Yearpart);
Date2 := datetimevalue(Yearnum, Monthnum, Daynum, hournum, minpart, 00)
I have a time field which displays as the following:
9:50:03 is 95003
14:53:44 is 145344
So when it's a single digit hour, the value is only 5 characters vs double digit hour is 6 characters.
I need to convert 95003 to 9:50 and 145344 to to 14:53 following this formula for any time.
If I were to do this in any language I would parse the data by 2 digits and add a : to each part. I would need to know what language to help you though. Or if it does not matter please emphasize.
This is very general without seeing your formula, but this is how I would go by doing it.
EDIT:
NumberVar dur := Sum ({#elapsed});
NumberVar hrs;
NumberVar min;
NumberVar sec;
StringVar hhmmss;
hrs := Truncate(Truncate(dur/60)/60);
min := Remainder(Truncate(dur/60),60);
sec :=Remainder(dur,60);
hhmmss :=totext(hrs,"00")+":"+totext(min,"00")+":"+totext(sec,"00");
Second Try
datediff("s",datetime(date({table.occdate}),{#enroutetimetotime}),datetime(date({table.inservicedate}),{#inservicetimetotime}))
OR - Probably your best shot
numbervar ntt := {YourTable.NumberField};
stringvar nttx := totext(ntt,"000000");
time(val(left(nttx,2)),val(mid(nttx,3,2)),val(right(nttx,2)))
I have two text fields in crystal report, textA and textB.
What if I wanted through the formula editor (not via c# code) set a third field called textTot = textA + textB.
What is the correct crystal report syntax?
Thanks a lot.
The simplist formula is: ToNumber({TableName.TextA}) + ToNumber({TableName.TextB}).
However, it would be a good idea to first test whether the data is numeric (to avoid a runtime error):
Local NumberVar numericA;
Local NumberVar numericB;
If IsNumeric(Trim({textA}))
Then numericA = ToNumber(Trim({textA}))
Else numericA = 0;
If IsNumeric(Trim({textB}))
Then numericB = ToNumber(Trim({textB}))
Else numericB = 0;
numericA + numericB;
I am working on this report pulls all of our Projected Purchases grouped by Month displaying a sum (called "Monthly_Total" for the month as well as displays the Budget (called "Monthly_Budget" for the month. I also have a subreport that I use a shared currencyvar "Starting_Balance". This shared variable updates whenever the report is run.
I need to find a way to do the following calculation:
for the first month (in this case the report starts with March) it should be
"Starting_Balance" + "Monthly_Total") - "Monthly_Budget" = "New_Balance"
each subsequent Month would use the formula
("New_Balance" + "Monthly_Total") - "Monthly_Budget"
I can get it to work for the first group footer, but with then each month after that is referencing back to the "Starting_Balance" rather than the "New_Balance"
any ideas?
Try using a flag variable that says whether or not the first month has been reported yet. I originally though of using New_Balance as 0, but that could potentially happen naturally.
So, something like
Initializer in the report header:
WhilePrintingRecords;
Global BooleanVar First_Month_Done := false; // have we printed the first month?
""; // print nothing on screen
Monthly formula
WhilePrintingRecords; // Optional when using shared variables
Global BooleanVar First_Month_Done;
Global CurrencyVar New_Balance; //or whatever it is
Shared CurrencyVar Starting_Balance;
// Assuming "Monthly_Total" and "Monthly_Budget" are formulas, not variables
If First_Month_Done
Then New_Balance := New_Balance + {#Monthly_Total} - {#Monthly_Budget}
Else New_Balance := Starting_Balance + {#Monthly_Total} - {#Monthly_Budget};
First_Month_Done := true;
New_Balance
Here is what I have. I have 15 unique formulas named Week1, Week2, ... Week15. I would like to be able to take a parameter name, MYCount, and use that to loop through the records and sum them. So if MyCount is equal to 3, the loop would sum Week1 + Week2 + Week3. I know how to create a loop, but I cannot figure out how to build the formula name dynamically. Here is what I have so far: (I am using Crystal Xi)
Whileprintingrecords;
local NumberVar i := {?MyCount}
For i := 1 To (MyCount-1) Do (
i = {#Week & "i"} + i
);
x
I think you may be over complicating. Why not just do:
Local numbervar x := 0;
If param > 0 then
X := x + week1;
If param > 1 then
X := x + week;
And so on...
X;
I don't exactly what you are trying to do, but you may want to consider another approach.
Create a formula that will segment a field based on a date field's week number:
//{#amount}
// adjust firstDayOfWeek and firstDayOfYear parameters to match your organization's
// definition of a week
If DatePart("ww", {table.dateField})<={?Week} Then
{table.amount}
Insert a summarized field on the formula field.
If you are using your #Weekn formula fields so that you can summarise by date across the page, then have you considered using Crystal's Crosstab functionality instead?