[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Problem with MOD and Integer.

Posted on 2004-08-05
3
Medium Priority
?
203 Views
Last Modified: 2010-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?
0
Comment
Question by:tobjectpascal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 26

Assisted Solution

by:Russell Libby
Russell Libby earned 400 total points
ID: 11725864

Seems like RDays should be the following

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

Where instead, you are dividing by 24 and then mod'ing by 24 (dividing will get the number of days, mod'ing will return the hours)

Regards,
Russell
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 100 total points
ID: 11726264
as rllibby wrote above:

function  Tform1.BuildTime(TimeVal: Int64): string;
var
  BuildStr:      string;
  RunTime:       Int64;
  RSec,Rhours,
  Rmins,Rdays:   Int64;
begin
  BuildStr := '';
  RunTime := TimeVal;
  RDays := Trunc(RunTime/60/60/24);
  if (Rdays=1) then
    BuildStr := BuildStr+' '+IntToStr(Rdays)+' day, '
  else
    BuildStr := BuildStr+' '+IntToStr(Rdays)+' days, ';
  RHours := Trunc(RunTime/60/60) mod 24;
  if (RHours=1) then
    BuildStr := BuildStr+IntToStr(Rhours)+' Hour, '
  else
    BuildStr := BuildStr+IntToStr(Rhours)+' Hours, ';
  RMins := Trunc(RunTime/60) mod 60;
  if (RMins=1) then
    BuildStr := BuildStr+IntToStr(RMins)+' Minute, '
  else
    BuildStr := BuildStr+IntToStr(RMins)+' Minutes, ';
  RSec := Trunc(RunTime/1) mod 60;
  if (RSec=1) then
    BuildStr := BuildStr+IntToStr(RSec)+' Second.'
  else
    BuildStr := BuildStr+IntToStr(RSec)+' Seconds.';
  Result := BuildStr;
end;

The poits are for rllibby, I just wrote it as code
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question