Solved

# Problem with MOD and Integer.

Posted on 2004-08-05

Anyone have a solution to this problem..

Function Tform1.BuildTime(TimeVal: Longint): string;

Var

BuildStr: String;

RunTime: Longint;

RSec,Rhours,Rmins,Rdays: Integer;

Begin

BuildStr:='';

RunTime:=TimeVal;

RDays:=Trunc(RunTime/60/60/24) mod 24 ;

If (Rdays>1) or (Rdays=0) Then

BuildStr:=BuildStr+' '+IntToStr(Rdays)+' days, '

else

BuildStr:=BuildStr+' '+IntToStr(Rdays)+' day, ';

RHours:=Trunc(RunTime/60/60) mod 24;

If (RHours>1) or (RHours=0) Then

BuildStr:=BuildStr+IntToStr(Rhours)+' Hours, '

else

BuildStr:=BuildStr+IntToStr(Rhours)+' Hour, ';

RMins:=Trunc(RunTime/60) mod 60;

If (RMins>1) or (RMins=0) Then

BuildStr:=BuildStr+IntToStr(RMins)+' Minutes, '

else

BuildStr:=BuildStr+IntToStr(RMins)+' Minute, ';

RSec:=Trunc(RunTime) Mod 60;

If (RSec>1) or (RSec=0) Then

BuildStr:=BuildStr+IntToStr(RSec)+' Seconds.'

else

BuildStr:=BuildStr+IntToStr(RSec)+' Second.';

Result:=BuildStr;

End;

//some button

Begin

//this gets how long your machine has been running for from

//get tick count

BuildStr:=BuildTime(Trunc(GetTickCount/1000));

ShowMessage(BuildStr);

End;

Problem is, after 22 days or so, MOD fails and goes back to 0

try 60 * 60 * 24 * 30 //60 seconds * 60 minutes * 24 hours * 30 days

And the result should be 30 day, the routine screws up giving something like 4 days, anyone know how solve this?