Sunday, February 19, 2012

Calculation gives different result on dev. machine and client machine

I have a report that takes in seconds and needs to calculate Hours:Minutes:Seconds. So I created a formula (called @.Duration, as follows). It works fine on my development machine, but when I deploy it to the Client machine, the Duration always comes up as 00:00:00 no matter how many seconds were passed to it. At first, I was thinking it could be due to an old dll on the Client machine, but I don't use anything aside from your basic mathematical Functions (+ - * / \) and basic String Functions (Right, CStr).

Does anyone have any idea what I can do to fix it?

//Code for Formula @.Duration

NumberVar nTimeLeft := {CallDuration};

NumberVar nHours := nTimeLeft \ 3600;
nTimeLeft := nTimeLeft - (nHours * 3600);

NumberVar nMinutes:= nTimeLeft \ 60;
nTimeLeft := nTimeLeft - (nMinutes * 60);

NumberVar nSeconds:= nTimeLeft;

//Sanity Check
IF (nHours * 3600) + (nMinutes * 60) + (nSeconds) = {CallDuration} THEN
Right ('0' + CStr(nHours), 2) + ':' + Right ('0' + CStr(nMinutes), 2) + ':' + Right ('0' + CStr(nSeconds), 2)
ELSE
CStr(nHours) + ':' + CStr(nMinutes) + ':' + CStr(nSeconds) + ' InvalidTime!';Found out why it's doing this, but need help fixing it...

On my machine, I have the default Number Format set up as ####. It seems that on the Client's machine (all of them), the default is #,###.00. As a result, my numbers would be displayed as follows:

1.00:2.00:3.00 for 1 hour, 2 minutes, and 3 seconds

when it should be displayed like this:

01:02:03

I have the code adding a leading zero, then taking the Right 2 characters to get it to display as 01 instead of 1. Since Crystal Formats the Numbers as 1.00, the Right function is capturing the 00 at the end and displaying like this:

00:00:00

Since the output is a string and not a number, there is no option (that I can see) for formatting the number before it's displayed.

Does anyone have any ideas on how I can get it to display properly?|||Problem solved...

I changed CStr(nHours) to ToText(nHours,0) and it worked. (The ',0' is the number of decimal places.)

No comments:

Post a Comment