Hi Paul,
What happens if you break the calc up?
ulong temp=JobStart - LineStart;
JobLeft = temp / TickPerPix;
(Everything is declared ulong so you shouldn't need the casts in the calc.)
If you use constants of the expected values in the calc does it still error?
I tried with; jobStart 1008E9 , LineStart 504E9 TickPerpix 909E6 and it
executed OK.
regards
Bob
"Paul Cheetham" <PA******@dsl.pipex.com> wrote in message
news:u1**************@TK2MSFTNGP15.phx.gbl...
Hi,
I am developing a program that is doinbg time calculations using Ticks.
Below is a piece of code that is causing an arithmetic overflow
exception - the single line inside the try statement.
All the variables are defined as ulong, the difference between JobStart
and LineStart is approx 584 000 000 000, and TicksPerPix is approx. 909
000 000
Can anyone see what I can't after staring at it for hours?
Thankyou.
Paul
ulong TicksPerPix, LineStart, JobStart, JobLeft;
TimeSpan time = _lineEndTime - _lineStartTime;
LineStart = (ulong)_lineStartTime.Ticks;
JobStart = (ulong)newJob.StartTime.Ticks;
TicksPerPix = (ulong)time.Ticks / (ulong)Width;
try
{ // The next line generates an Arithmetic Overflow!
JobLeft = ((ulong)(JobStart - LineStart) / (ulong)TicksPerPix);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception");
}